Ejemplo n.º 1
0
        public ActionResult CreateOrEditClinic()
        {
            ClinicResponse _response = new ClinicResponse();

            if (Request.QueryString["id"] != null)
            {
                var request = new ClinicRequest
                {
                    Data = new ClinicModel
                    {
                        Id = long.Parse(Request.QueryString["id"].ToString())
                    }
                };

                ClinicResponse resp   = new ClinicHandler(_unitOfWork).GetDetail(request);
                ClinicModel    _model = resp.Entity;
                ViewBag.Response    = _response;
                ViewBag.Cities      = BindDropDownCity();
                ViewBag.ClinicTypes = BindDropDownClinicType();
                ViewBag.ActionType  = ClinicEnums.Action.Edit;
                return(View(_model));
            }
            else
            {
                ViewBag.Response    = _response;
                ViewBag.Cities      = BindDropDownCity();
                ViewBag.ClinicTypes = BindDropDownClinicType();
                ViewBag.ActionType  = ClinicEnums.Action.Add;
                return(View());
            }
        }
Ejemplo n.º 2
0
        public async Task <ClinicResponse> GetClinicByName(ClinicRequest values, PageFilter filter)
        {
            ClinicResponse _response = new ClinicResponse();

            try
            {
                List <ClinicsEntity> results = await _context.Clinics.Where(x => x.IsDeleted == false).Where(x => x.Name.Contains(values.Name)).OrderByDynamic(filter.Column, filter.Descending).Skip(filter.Index * filter.Count).Take(filter.Count).ToListAsync();

                _response.Code      = "E000";
                _response.Message   = _localizer["success"];
                _response.DataCount = await _context.Clinics.Where(x => x.IsDeleted == false).Where(x => x.Name.Contains(values.Name)).CountAsync();

                _response.ResponseDate = DateTime.Now.ToUniversalTime();
                _response.Results.AddRange(results);
            }
            catch (Exception ex)
            {
                _response.Code         = "E999";
                _response.Message      = ex.Message;
                _response.DataCount    = 0;
                _response.ResponseDate = DateTime.Now.ToUniversalTime();
                _response.Results      = null;
            }
            return(_response);
        }
Ejemplo n.º 3
0
        public ActionResult GetClinic()
        {
            var _draw          = Request.Form.GetValues("draw").FirstOrDefault();
            var _start         = Request.Form.GetValues("start").FirstOrDefault();
            var _length        = Request.Form.GetValues("length").FirstOrDefault();
            var _sortColumn    = Request.Form.GetValues("columns[" + Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][name]").FirstOrDefault();
            var _sortColumnDir = Request.Form.GetValues("order[0][dir]").FirstOrDefault();
            var _searchValue   = Request.Form.GetValues("search[value]").FirstOrDefault();

            int _pageSize = _length != null?Convert.ToInt32(_length) : 0;

            int _skip = _start != null?Convert.ToInt32(_start) : 0;

            var request = new ClinicRequest
            {
                Draw          = _draw,
                SearchValue   = _searchValue,
                SortColumn    = _sortColumn,
                SortColumnDir = _sortColumnDir,
                PageSize      = _pageSize,
                Skip          = _skip
            };

            var response = new ClinicHandler(_unitOfWork).GetListData(request);

            return(Json(new { data = response.Data, recordsFiltered = response.RecordsFiltered, recordsTotal = response.RecordsTotal, draw = response.Draw }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 4
0
        public JsonResult searchklinik(string prefix)
        {
            var _draw          = "1";
            var _start         = "0";
            var _length        = "10";
            var _sortColumn    = "Id";
            var _sortColumnDir = "asc";
            var _searchValue   = prefix;

            int _pageSize = _length != null?Convert.ToInt32(_length) : 0;

            int _skip = _start != null?Convert.ToInt32(_start) : 0;

            var request = new ClinicRequest
            {
                Draw          = _draw,
                SearchValue   = _searchValue,
                SortColumn    = _sortColumn,
                SortColumnDir = _sortColumnDir,
                PageSize      = _pageSize,
                Skip          = _skip
            };
            var response = new ClinicResponse();

            if (request.SearchValue != null)
            {
                response = new ClinicHandler(_unitOfWork).GetAllData(request);
            }

            return(Json(new { data = response.Data, recordsFiltered = response.RecordsFiltered, recordsTotal = response.RecordsTotal, draw = response.Draw }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Validate the request
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        public void Validate(ClinicRequest request, out ClinicResponse response)
        {
            response = new ClinicResponse();

            if (request.Action != null && request.Action.Equals(ClinicEnums.Action.DELETE.ToString()))
            {
                ValidateForDelete(request, out response);
            }
            else
            {
                bool isHavePrivilege = true;

                if (String.IsNullOrEmpty(request.Data.Code) || String.IsNullOrWhiteSpace(request.Data.Code))
                {
                    errorFields.Add("Clinic Code");
                }

                if (String.IsNullOrEmpty(request.Data.Name) || String.IsNullOrWhiteSpace(request.Data.Name))
                {
                    errorFields.Add("Clinic Name");
                }

                if (!String.IsNullOrEmpty(request.Data.Email))
                {
                    if (!Regex.IsMatch(request.Data.Email, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$|^\+?\d{0,2}\-?\d{4,5}\-?\d{5,6}"))
                    {
                        errorFields.Add("Email");
                    }
                }

                if (errorFields.Any())
                {
                    response.Status  = false;
                    response.Message = string.Format(Messages.ValidationErrorFields, String.Join(",", errorFields));
                }

                if (request.Data.Id == 0)
                {
                    isHavePrivilege = IsHaveAuthorization(ADD_PRIVILEGE_NAME, request.Data.Account.Privileges.PrivilegeIDs);
                }
                else
                {
                    isHavePrivilege = IsHaveAuthorization(EDIT_PRIVILEGE_NAME, request.Data.Account.Privileges.PrivilegeIDs);
                }

                if (!isHavePrivilege)
                {
                    response.Status  = false;
                    response.Message = Messages.UnauthorizedAccess;
                }

                if (response.Status)
                {
                    response = new ClinicHandler(_unitOfWork).CreateOrEdit(request);
                }
            }
        }
Ejemplo n.º 6
0
        public ClinicResponse GetClientByGuid(ClinicRequest value, PageFilter filter)
        {
            string request = ToStringRequestBuilder.NewInstance()
                             .AppendGetMethod("Name", value.Name)
                             .AppendGetMethod("Column", filter.Column)
                             .AppendGetMethod("Descending", filter.Descending.ToString())
                             .AppendGetMethod("Index", filter.Index.ToString())
                             .AppendGetMethod("Count", filter.Count.ToString())
                             .GetRequestString();

            return(RestHttpClient.Create().Get <ClinicResponse>("https://localhost:44331/clinics/get-by-name?" + request));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Get employee details
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public ClinicResponse GetDetail(ClinicRequest request)
        {
            ClinicResponse response = new ClinicResponse();

            var qry = _unitOfWork.ClinicRepository.Query(x => x.ID == request.Data.Id);

            if (qry.FirstOrDefault() != null)
            {
                response.Entity = Mapper.Map <Clinic, ClinicModel>(qry.FirstOrDefault());
            }

            return(response);
        }
Ejemplo n.º 8
0
        public JsonResult DeleteMasterClinic(int id)
        {
            ClinicResponse _response = new ClinicResponse();
            var            request   = new ClinicRequest
            {
                Data = new ClinicModel
                {
                    Id      = id,
                    Account = Session["UserLogon"] == null ? new AccountModel() : (AccountModel)Session["UserLogon"]
                },
                Action = ClinicEnums.Action.DELETE.ToString()
            };

            new ClinicValidator(_unitOfWork).Validate(request, out _response);

            return(Json(new { Status = _response.Status, Message = _response.Message }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Delete validation
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        private void ValidateForDelete(ClinicRequest request, out ClinicResponse response)
        {
            response = new ClinicResponse();

            if (request.Action == ClinicEnums.Action.DELETE.ToString())
            {
                bool isHavePrivilege = IsHaveAuthorization(DELETE_PRIVILEGE_NAME, request.Data.Account.Privileges.PrivilegeIDs);
                if (!isHavePrivilege)
                {
                    response.Status  = false;
                    response.Message = Messages.UnauthorizedAccess;
                }
            }

            if (response.Status)
            {
                response = new ClinicHandler(_unitOfWork).RemoveData(request);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Remove employee data
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public ClinicResponse RemoveData(ClinicRequest request)
        {
            ClinicResponse response = new ClinicResponse();

            try
            {
                var clinic = _unitOfWork.ClinicRepository.GetById(request.Data.Id);
                if (clinic.ID > 0)
                {
                    clinic.RowStatus    = -1;
                    clinic.ModifiedBy   = request.Data.Account.UserCode;
                    clinic.ModifiedDate = DateTime.Now;

                    _unitOfWork.ClinicRepository.Update(clinic);
                    int resultAffected = _unitOfWork.Save();
                    if (resultAffected > 0)
                    {
                        response.Message = string.Format(Messages.ObjectHasBeenRemoved, "Clinic", clinic.Name, clinic.Code);
                    }
                    else
                    {
                        response.Status  = false;
                        response.Message = string.Format(Messages.RemoveObjectFailed, "Clinic");
                    }
                }
                else
                {
                    response.Status  = false;
                    response.Message = string.Format(Messages.RemoveObjectFailed, "Clinic");
                }
            }
            catch (Exception ex)
            {
                response.Status  = false;
                response.Message = Messages.GeneralError;

                ErrorLog(ClinicEnums.Module.MASTER_CLINIC, ClinicEnums.Action.DELETE.ToString(), request.Data.Account, ex);
            }

            return(response);
        }
Ejemplo n.º 11
0
        public async Task <ClinicResponse> UpdateClinicByGuid(string guid, ClinicRequest values)
        {
            ClinicResponse _response = new ClinicResponse();

            try
            {
                ClinicsEntity clinic = await _context.Clinics.Where(x => x.ClinicGuid == guid && x.IsDeleted == false).FirstOrDefaultAsync();

                if (clinic == null)
                {
                    _response.Code         = "E001";
                    _response.Message      = _localizer["norecords"];
                    _response.DataCount    = 0;
                    _response.ResponseDate = DateTime.Now.ToUniversalTime();
                    _response.Results      = null;
                }
                else
                {
                    if (!string.IsNullOrEmpty(values.Name))
                    {
                        clinic.Name = values.Name;
                        await _context.SaveChangesAsync();
                    }
                    _response.Code         = "E000";
                    _response.Message      = _localizer["success"];
                    _response.DataCount    = 1;
                    _response.ResponseDate = DateTime.Now.ToUniversalTime();
                    _response.Results.Add(clinic);
                }
            }
            catch (Exception ex)
            {
                _response.Code         = "E999";
                _response.Message      = ex.Message;
                _response.DataCount    = 0;
                _response.ResponseDate = DateTime.Now.ToUniversalTime();
                _response.Results      = null;
            }

            return(_response);
        }
Ejemplo n.º 12
0
        public ActionResult CreateOrEditClinic(ClinicModel _model)
        {
            if (Session["UserLogon"] != null)
            {
                _model.Account = (AccountModel)Session["UserLogon"];
            }

            var request = new ClinicRequest
            {
                Data = _model
            };

            ClinicResponse _response = new ClinicResponse();

            new ClinicValidator(_unitOfWork).Validate(request, out _response);
            ViewBag.Response    = $"{_response.Status};{_response.Message}";
            ViewBag.Cities      = BindDropDownCity();
            ViewBag.ClinicTypes = BindDropDownClinicType();
            ViewBag.ActionType  = request.Data.Id > 0 ? ClinicEnums.Action.Edit : ClinicEnums.Action.Add;

            return(View());
        }
Ejemplo n.º 13
0
        public ActionResult ClinicPoliList()
        {
            ClinicPoliModel rpmodel = new ClinicPoliModel();

            if (Request.QueryString["clinicid"] != null)
            {
                var reqOrg = new ClinicRequest
                {
                    Data = new ClinicModel
                    {
                        Id = Convert.ToInt64(Request.QueryString["clinicid"].ToString())
                    }
                };

                var respOrg = new ClinicResponse();
                respOrg            = new ClinicHandler(_unitOfWork).GetDetail(reqOrg);
                rpmodel.ClinicName = respOrg.Entity.Name;
                rpmodel.ClinicID   = respOrg.Entity.Id;

                var _request = new ClinicPoliRequest
                {
                    Data = new ClinicPoliModel
                    {
                        ClinicID = Convert.ToInt64(Request.QueryString["clinicid"].ToString())
                    }
                };
                //get Privilege Ids for organization
                var selPolis = new ClinicPoliHandler(_unitOfWork, _context).GetListData(_request);
                if (selPolis.Entity.PoliIDs != null && selPolis.Entity.PoliIDs.Count > 0)
                {
                    rpmodel.PoliIDs = selPolis.Entity.PoliIDs;
                }
            }

            return(View(rpmodel));
        }
 public async Task <ClinicResponse> GetByName([FromQuery] ClinicRequest value, [FromQuery] PageFilter filter)
 {
     return(await _clinics.GetClinicByName(value, filter));
 }
Ejemplo n.º 15
0
        public ClinicResponse GetAllData(ClinicRequest request)
        {
            List <ClinicModel> lists = new List <ClinicModel>();
            dynamic            qry   = null;
            var searchPredicate      = PredicateBuilder.New <Clinic>(true);

            // add default filter to show the active data only
            searchPredicate = searchPredicate.And(x => x.RowStatus == 0);

            if (!String.IsNullOrEmpty(request.SearchValue) && !String.IsNullOrWhiteSpace(request.SearchValue))
            {
                searchPredicate = searchPredicate.And(p => p.Code.Contains(request.SearchValue) || p.Name.Contains(request.SearchValue));
            }

            if (!(string.IsNullOrEmpty(request.SortColumn) && string.IsNullOrEmpty(request.SortColumnDir)))
            {
                if (request.SortColumnDir == "asc")
                {
                    switch (request.SortColumn.ToLower())
                    {
                    case "code":
                        qry = _unitOfWork.ClinicRepository.Get(searchPredicate, orderBy: q => q.OrderBy(x => x.Code));
                        break;

                    case "name":
                        qry = _unitOfWork.ClinicRepository.Get(searchPredicate, orderBy: q => q.OrderBy(x => x.Name));
                        break;

                    default:
                        qry = _unitOfWork.ClinicRepository.Get(searchPredicate, orderBy: q => q.OrderBy(x => x.ID));
                        break;
                    }
                }
                else
                {
                    switch (request.SortColumn.ToLower())
                    {
                    case "code":
                        qry = _unitOfWork.ClinicRepository.Get(searchPredicate, orderBy: q => q.OrderByDescending(x => x.Code));
                        break;

                    case "name":
                        qry = _unitOfWork.ClinicRepository.Get(searchPredicate, orderBy: q => q.OrderByDescending(x => x.Name));
                        break;

                    default:
                        qry = _unitOfWork.ClinicRepository.Get(searchPredicate, orderBy: q => q.OrderByDescending(x => x.ID));
                        break;
                    }
                }
            }
            else
            {
                qry = _unitOfWork.ClinicRepository.Get(searchPredicate, null);
            }

            foreach (var item in qry)
            {
                var  clinicData        = Mapper.Map <Clinic, ClinicModel>(item);
                long _cityId           = clinicData.CityId ?? 0;
                long _clinicTypeId     = clinicData.ClinicType ?? 0;
                var  getCityDesc       = _unitOfWork.MasterRepository.GetFirstOrDefault(x => x.ID == _cityId && x.Type == ClinicEnums.MasterTypes.City.ToString());
                var  getClinicTypeDesc = _unitOfWork.MasterRepository.GetFirstOrDefault(x => x.ID == _clinicTypeId && x.Type == ClinicEnums.MasterTypes.ClinicType.ToString());
                if (getCityDesc != null)
                {
                    clinicData.CityDesc = getCityDesc.Name ?? "";
                }
                if (getClinicTypeDesc != null)
                {
                    clinicData.ClinicTypeDesc = getClinicTypeDesc.Name ?? "";
                }

                lists.Add(clinicData);
            }

            int totalRequest = lists.Count();
            var data         = lists.Skip(request.Skip).Take(request.PageSize).ToList();

            var response = new ClinicResponse
            {
                Draw            = request.Draw,
                RecordsFiltered = totalRequest,
                RecordsTotal    = totalRequest,
                Data            = data
            };

            return(response);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Create or edit a clinic
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public ClinicResponse CreateOrEdit(ClinicRequest request)
        {
            ClinicResponse response = new ClinicResponse();

            try
            {
                if (request.Data.Id > 0)
                {
                    var qry = _unitOfWork.ClinicRepository.GetById(request.Data.Id);
                    if (qry != null)
                    {
                        // save the old data
                        var _oldentity = Mapper.Map <Clinic, ClinicModel>(qry);

                        // update data
                        qry.Name          = request.Data.Name;
                        qry.Address       = request.Data.Address;
                        qry.LegalNumber   = request.Data.LegalNumber;
                        qry.LegalDate     = request.Data.LegalDate;
                        qry.ContactNumber = request.Data.ContactNumber;
                        qry.Email         = request.Data.Email;
                        qry.Lat           = request.Data.Lat;
                        qry.Long          = request.Data.Long;
                        qry.CityID        = request.Data.CityId;
                        qry.ClinicType    = request.Data.ClinicType;
                        qry.ModifiedDate  = DateTime.Now;
                        qry.ModifiedBy    = request.Data.ModifiedBy ?? "SYSTEM";

                        _unitOfWork.ClinicRepository.Update(qry);
                        int resultAffected = _unitOfWork.Save();
                        if (resultAffected > 0)
                        {
                            response.Message = string.Format(Messages.ObjectHasBeenUpdated, "Clinic", qry.Name, qry.Code);

                            CommandLog(true, ClinicEnums.Module.MASTER_CLINIC, Constants.Command.EDIT_CLINIC, request.Data.Account, request.Data, _oldentity);
                        }
                        else
                        {
                            response.Status  = false;
                            response.Message = string.Format(Messages.UpdateObjectFailed, "Clinic");

                            CommandLog(false, ClinicEnums.Module.MASTER_CLINIC, Constants.Command.EDIT_CLINIC, request.Data.Account, request.Data, _oldentity);
                        }
                    }
                    else
                    {
                        response.Status  = false;
                        response.Message = string.Format(Messages.UpdateObjectFailed, "Clinic");

                        CommandLog(false, ClinicEnums.Module.MASTER_CLINIC, Constants.Command.EDIT_CLINIC, request.Data.Account, request.Data);
                    }
                }
                else
                {
                    var clinicEntity = Mapper.Map <ClinicModel, Clinic>(request.Data);
                    clinicEntity.CreatedBy   = request.Data.Account.UserCode;
                    clinicEntity.CreatedDate = DateTime.Now;

                    _unitOfWork.ClinicRepository.Insert(clinicEntity);

                    int resultAffected = _unitOfWork.Save();
                    if (resultAffected > 0)
                    {
                        response.Message = string.Format(Messages.ObjectHasBeenAdded, "Clinic", clinicEntity.Name, clinicEntity.Code);

                        CommandLog(true, ClinicEnums.Module.MASTER_CLINIC, Constants.Command.ADD_NEW_CLINIC, request.Data.Account, request.Data);
                    }
                    else
                    {
                        response.Status  = false;
                        response.Message = string.Format(Messages.AddObjectFailed, "Clinic");

                        CommandLog(false, ClinicEnums.Module.MASTER_CLINIC, Constants.Command.ADD_NEW_CLINIC, request.Data.Account, request.Data);
                    }
                }
            }
            catch (Exception ex)
            {
                response.Status  = false;
                response.Message = Messages.GeneralError;

                if (request.Data != null && request.Data.Id > 0)
                {
                    ErrorLog(ClinicEnums.Module.MASTER_CLINIC, Constants.Command.EDIT_CLINIC, request.Data.Account, ex);
                }
                else
                {
                    ErrorLog(ClinicEnums.Module.MASTER_CLINIC, Constants.Command.ADD_NEW_CLINIC, request.Data.Account, ex);
                }
            }

            return(response);
        }
 public async Task <ClinicResponse> Update([FromQuery] string guid, [FromBody] ClinicRequest values)
 {
     return(await _clinics.UpdateClinicByGuid(guid, values));
 }