public static string GetNameById(Guid id)
        {
            try
            {
                UserDetailModel model = new UserDetailModel();
                using (var db = new HMSEntities())
                {
                    UserDetail entity = db.UserDetails.Find(id);
                    if (entity != null)
                    {
                        return(entity.FullName);
                    }
                }

                return(string.Empty);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public bool Create(UserDetailModel model)
        {
            try
            {
                bool isSaved = false;

                if (!IsExist(model))
                {
                    using (var db = new HMSEntities())
                    {
                        UserDetail entity = new UserDetail();

                        entity.FullName       = model.FullName;
                        entity.Address        = model.Address;
                        entity.PhoneNumber    = model.PhoneNumber;
                        entity.DepartmentId   = Department.GetByName("OPD").Id;
                        entity.RoleCategoryId = RoleCategory.GetByName("Genaral").Id;
                        entity.UserName       = model.UserName;
                        entity.Password       = model.Password;
                        entity.IsActive       = true;
                        entity.IsDeleted      = false;
                        entity.CreatedOn      = DateTime.Now;
                        entity.CreatedBy      = UserDetailSession.Id;

                        db.UserDetails.Add(entity);
                        db.SaveChanges();

                        isSaved = true;
                    }
                }


                return(isSaved);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public bool Update(UserDetailModel model)
        {
            try
            {
                bool isSaved = false;

                if (!IsExist(model))
                {
                    using (var db = new HMSEntities())
                    {
                        UserDetail entity = db.UserDetails.Find(model.Id);

                        entity.FullName       = model.FullName;
                        entity.Address        = model.Address;
                        entity.PhoneNumber    = model.PhoneNumber;
                        entity.DepartmentId   = UserDetailSession.DepartmentId;
                        entity.RoleCategoryId = UserDetailSession.RoleCategoryId;
                        entity.UserName       = model.UserName;
                        entity.Password       = model.Password;
                        entity.ModifiedOn     = DateTime.Now;
                        entity.ModifiedBy     = UserDetailSession.Id;

                        db.SaveChanges();

                        isSaved = true;
                    }
                }


                return(isSaved);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public UserDetailModel GetByParentId(Guid id)
        {
            try
            {
                UserDetailModel model = new UserDetailModel();
                using (var db = new HMSEntities())
                {
                    UserDetail entity = db.UserDetails.FirstOrDefault(t => t.DepartmentId == id);
                    if (entity != null)
                    {
                        model.Id               = entity.Id;
                        model.FullName         = entity.FullName;
                        model.Address          = entity.Address;
                        model.PhoneNumber      = entity.PhoneNumber;
                        model.DepartmentId     = entity.DepartmentId;
                        model.DepartmentName   = entity.Department.Name;
                        model.RoleCategoryId   = entity.RoleCategoryId;
                        model.RoleCategoryName = entity.RoleCategory.Name;
                        model.UserName         = entity.UserName;
                        model.Password         = entity.Password;
                        model.IsActive         = entity.IsActive;
                        model.IsDeleted        = entity.IsDeleted;
                        model.CreatedOn        = entity.CreatedOn;
                        model.CreatedBy        = entity.CreatedBy;
                        model.ModifiedOn       = entity.ModifiedOn;
                        model.ModifiedBy       = entity.ModifiedBy;
                    }
                }

                return(model);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }