Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Use of Region in coding

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 52
    Comment on it

    While writing code to make a clear separation of working modules and codes you need to separate the blocks functions properties and classes so that understanding of the code is more effective

    public interface INudgeService
        {
            #region "==== Operation Contract ===="
    
            /// <summary>
            /// To add user details into the database
            /// </summary>
            /// <param name="emp"></param>
            /// <returns>Return message,status and last inserted employee record</returns>
            [OperationContract]
            [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Bare,
            UriTemplate = "Register")]
            EmployeeResponse RegisterUser(EmployeeRequest emp);
    
            /// <summary>
            /// To authenticate user
            /// </summary>
            /// <param name="emp"></param>
            /// <returns>Return message,status and  employee record</returns>
            [OperationContract]
            [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
                BodyStyle = WebMessageBodyStyle.Bare,
                UriTemplate = "CheckLogin")]
            EmployeeResponse LoginUser(EmployeeRequest emp);
    
            /// <summary>
            ///To delete nudge of the user stored in the database
            /// </summary>
            /// <param name="accessToken"></param>
            /// <param name="Id"></param>
            /// <returns>Returns message status and nudge details</returns>
            [OperationContract]
            [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "Delete")]
            NudgeDetailResponse DeleteNudge(string accessToken, int Id);
    
            /// <summary>
            /// To show content/details of the user stored in the database
            /// </summary>
            /// <param name="accessToken"></param>
            /// <returns>Return message,status and  employee record</returns>
            [OperationContract]
            [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "UserProfile")]
            EmployeeResponse GetUserProfile(string accessToken);
    
            /// <summary>
            /// To send nudge details/messages of the user to the friends
            /// </summary>
            /// <param name="accessToken"></param>
            /// <returns>Return message,status and  employee record list</returns>
            [OperationContract]
            [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "NudgeFriends")]
            EmployeeListResponse GetFriendsToNudge(string accessToken);
    
            /// <summary>
            /// To change user details stored in the database
            /// </summary>
            /// <param name="emp"></param>
            /// <returns>Return message,status and  employee record</returns>
            [OperationContract]
            [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Bare,
            UriTemplate = "UpdateUserProfile")]
            EmployeeResponse UpdateUserProfile(EmployeeRequest emp);
    
            /// <summary>
            /// To reset user password stored in the database
            /// </summary>
            /// <param name="Email"></param>
            /// <returns>Return message,status and  employee record</returns>
            [OperationContract]
            [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "ForgotPassword")]
            EmployeeResponse ForgotPassword(string Email);
    
            /// <summary>
            ///  To log out user
            /// </summary>
            /// <param name="accessToken"></param>
            /// <returns>Return message,status and  employee record</returns>
            [OperationContract]
            [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "LogOut")]
            EmployeeResponse LogOut(string accessToken);
    
            /// <summary>
            /// To find all the locations associated to the nudges
            /// </summary>
            /// <param name="accessToken"></param>
            /// <returns>Return message,status and  employee record</returns>
            [OperationContract]
            [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "GetNudgeLocation")]
            LocationListResponse GetNudgeLocation(string accessToken);
    
            /// <summary>
            /// To send and display the nudge send by someone to the particular user
            /// </summary>
            /// <param name="accessToken"></param>
            /// <returns>Return message,status and  nudge details</returns>
            [OperationContract]
            [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "GetEmployeeNudge")]
            NudgeListDetailsResponse GetEmployeeNudge(string accessToken);
    
            /// <summary>
            ///  To save nudge of the user for their friends
            /// </summary>
            /// <param name="nudgeRequest"></param>
            /// <returns>Return message,status and  nudge list details</returns>
            [OperationContract]
            [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Bare,
            UriTemplate = "SaveNudge")]
            NudgeDetailResponse SaveNudgeForFriend(NudgeListRequest nudgeRequest);
    
            /// <summary>
            /// To get all the details of the company for creating nudges that is stored into the database 
            /// </summary>
            /// <returns>Return message,status and  company details</returns>
            [OperationContract]
            [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Bare,
            UriTemplate = "GetCompany")]
            CompanyResponse GetCompany();
    
            /// <summary>
            /// To get all the roles associated with the users that is stored into the database 
            /// </summary>
            /// <returns>Return message,status and  role details</returns>
            [OperationContract]
            [WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Bare,
            UriTemplate = "GetRoles")]
            JobRoleResponse GetJobRoles();
        }
    
        #endregion
    
        #region "==== Employee Model ===="
        /// <summary>
        /// To pass as request for employee operations 
        /// </summary>
        [DataContract]
        public class EmployeeRequest
        {
            [DataMember]
            public int Id { get; set; }
            [DataMember]
            public string AccessToken { get; set; }
            [DataMember]
            public string CompanyId { get; set; }
            [DataMember]
            public string Company { get; set; }
            [DataMember]
            public string DeviceType { get; set; }
            [DataMember]
            public string DeviceUUID { get; set; }
            [DataMember]
            public string Email { get; set; }
            [DataMember]
            public string FirstName { get; set; }
            [DataMember]
            public string JobRoleID { get; set; }
            [DataMember]
            public string LastName { get; set; }
            [DataMember]
            public string FullName { get; set; }
            [DataMember]
            public string Password { get; set; }
            [DataMember]
            public bool IsDeleted { get; set; }
            [DataMember]
            public string ProfileImage { get; set; }
            [DataMember]
            public byte[] ProfileImageByteArray { get; set; }
        }
    
        /// <summary>
        /// To pass as list for multiple employees
        /// </summary>
        [DataContract]
        public class EmployeeList
        {
            [DataMember]
            public int ID { get; set; }
            [DataMember]
            public string FullName { get; set; }
        }
    
        /// <summary>
        /// For single employee response
        /// </summary>
        [DataContract]
        public class EmployeeResponse
        {
            [DataMember]
            public string Message { get; set; }
            [DataMember]
            public bool Status { get; set; }
            [DataMember]
            public string accessToken { get; set; }
            [DataMember]
            public EmployeeRequest data { get; set; }
        }
    
        /// <summary>
        /// For multiple employee response
        /// </summary>
        [DataContract]
        public class EmployeeListResponse
        {
            [DataMember]
            public string Message { get; set; }
            [DataMember]
            public bool Status { get; set; }
            [DataMember]
            public List<EmployeeList> employeelist { get; set; }
        }
        #endregion
    
        #region "==== Nudge Model ===="
        /// <summary>
        ///  Send request while manipulating with Nudge
        /// </summary>
        [DataContract]
        public class NudgeListRequest
        {
            [DataMember]
            public string Message { get; set; }
            [DataMember]
            public int TargetUserID { get; set; }
            [DataMember]
            public string AccessToken { get; set; }
            [DataMember]
            public int DaysTillExpire { get; set; }
            [DataMember]
            public int HoursTillExpire { get; set; }
            [DataMember]
            public int LocationID { get; set; }
            [DataMember]
            public string CreatedBy { get; set; }
            [DataMember]
            public string CreatedDate { get; set; }
            [DataMember]
            public int ID { get; set; }
            [DataMember]
            public string Location { get; set; }
            [DataMember]
            public string TargetUser { get; set; }
            [DataMember]
            public string Company { get; set; }
    
        }
    
        /// <summary>
        ///  For single nudge
        /// </summary>
        [DataContract]
        public class NudgeDetailResponse
        {
            [DataMember]
            public string Message { get; set; }
            [DataMember]
            public bool Status { get; set; }
            [DataMember]
            public NudgeListRequest data { get; set; }
        }
    
        /// <summary>
        /// For multiple nudge
        /// </summary>
        [DataContract]
        public class NudgeListDetailsResponse
        {
            [DataMember]
            public string Message { get; set; }
            [DataMember]
            public bool Status { get; set; }
            [DataMember]
            public List<NudgeListRequest> data { get; set; }
        }
        #endregion
    
        #region "==== Location Model ===="
        /// <summary>
        /// For creating location request
        /// </summary>
        public class LocationDetails
        {
            [DataMember()]
            public int ID { get; set; }
            [DataMember()]
            public string CompanyID { get; set; }
            [DataMember()]
            public string Company { get; set; }
            [DataMember()]
            public string Location { get; set; }
            [DataMember()]
            public string BeaconUUID { get; set; }
            [DataMember()]
            public string BeaconMajor { get; set; }
            [DataMember()]
            public string BeaconMinor { get; set; }
            [DataMember()]
            public string AccessToken { get; set; }
        }
    
        /// <summary>
        /// To pass as list for multiple locations
        /// </summary>
        [DataContract]
        public class LocationList
        {
            [DataMember]
            public int ID { get; set; }
            [DataMember]
            public string Location { get; set; }
        }
    
        /// <summary>
        /// For providing location response
        /// </summary>
        [DataContract]
        public class LocationListResponse
        {
            [DataMember]
            public string Message { get; set; }
            [DataMember]
            public bool status { get; set; }
            [DataMember]
            public List<LocationList> data { get; set; }
        }
        #endregion
    
        #region "==== Company Model ===="
        /// <summary>
        /// For passing company as list in response
        /// </summary>
        [DataContract()]
        public class CompanyList
        {
            [DataMember()]
            public string Company { get; set; }
            [DataMember]
            public int ID { get; set; }
        }
    
        /// <summary>
        /// For providing company response
        /// </summary>
        [DataContract()]
        public class CompanyResponse
        {
            [DataMember()]
            public List<CompanyList> data { get; set; }
            [DataMember]
            public bool status { get; set; }
            [DataMember()]
            public string Message { get; set; }
        }
        #endregion
    
        #region "==== Job Model ===="
        /// <summary>
        /// For passing joblist as list in response
        /// </summary>
        [DataContract()]
        public class JobList
        {
            [DataMember]
            public int ID { get; set; }
            [DataMember()]
            public string JobRole { get; set; }
        }
    
        /// <summary>
        /// For providing job response
        /// </summary>
        [DataContract()]
        public class JobRoleResponse
        {
            [DataMember()]
            public List<JobList> data { get; set; }
            [DataMember]
            public bool status { get; set; }
            [DataMember()]
            public string Message { get; set; }
        }
        #endregion
    }
    

    You can make the code easy by minimizing everything inside regions

     

    Now your code looks like this

        #region "==== Job Model ===="
        /// <summary>
        /// For passing joblist as list in response
        /// </summary>
        [DataContract()]
        public class JobList
        {
            [DataMember]
            public int ID { get; set; }
            [DataMember()]
            public string JobRole { get; set; }
        }
    
        /// <summary>
        /// For providing job response
        /// </summary>
        [DataContract()]
        public class JobRoleResponse
        {
            [DataMember()]
            public List<JobList> data { get; set; }
            [DataMember]
            public bool status { get; set; }
            [DataMember()]
            public string Message { get; set; }
        }
        #endregion
    

    Which is more easy to understand and make separation between the methods and properties

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: