public bool CreateMedicineRequest(MedicineRequest request)
        {
            using (UserContext c = new UserContext())
            {
                var req = c.MedicineRequests.Where(x => x.requestId == request.requestId && request.deleted == false).FirstOrDefault();
                if (req != null)
                {
                    req.deleted         = request.deleted;
                    req.requestResponse = request.requestResponse;

                    c.Update(req);
                }
                else
                {
                    byte[] imageArray = System.IO.File.ReadAllBytes(request.requestImage);
                    string base64ImageRepresentation = Convert.ToBase64String(imageArray);

                    request.requestImage = base64ImageRepresentation;

                    c.MedicineRequests.Add(request);
                }
                c.SaveChanges();
                return(true);
            }
        }
Пример #2
0
 public static List <MedicineRequest> StartListeningForMedicineRequests(UserToken userToken)
 {
     try
     {
         using (var db = new DatabaseMedAssistEntities())
         {
             var query = from request in db.DatabaseRequests
                         where request.ReceiverID == userToken.userInfo.UserID
                         select request;
             var medicine = from requests in query
                            group requests by requests.SenderID;
             List <Medicine>        medicines        = new List <Medicine>();
             List <MedicineRequest> medicineRequests = new List <MedicineRequest>();
             int id = 1;
             foreach (var item in medicine)
             {
                 var             sender          = db.DatabaseUsers.SingleOrDefault(k => k.UserID == item.Key);
                 MedicineRequest medicineRequest = new MedicineRequest
                 {
                     ID         = id,
                     IsLocked   = true,
                     SenderName = sender.Nama,
                 };
                 int currentItem = 0;
                 foreach (var request in item)
                 {
                     if (currentItem == 0)
                     {
                         GeoCoordinate requestLocation = new GeoCoordinate(Convert.ToDouble(request.LocationLatitude), Convert.ToDouble(request.LocationLongitude));
                         medicineRequest.Location       = requestLocation;
                         medicineRequest.LocationDetail = request.LocationDetail;
                     }
                     string[] details = request.RequestDetail.Split(',');
                     Medicine order   = new Medicine
                     {
                         MedicineName = request.Request,
                         Quantity     = Convert.ToInt32(details[0]),
                         Price        = Convert.ToDouble(details[1])
                     };
                     medicines.Add(order);
                     currentItem++;
                     var result = db.DatabaseRequests.SingleOrDefault(k => k.SenderID == item.Key && k.Request == request.Request);
                     result.IsLocked = true;
                 }
                 medicineRequest.Medicines = medicines;
                 medicineRequests.Add(medicineRequest);
             }
             db.SaveChanges();
             return(medicineRequests);
         }
     }
     catch (Exception ex)
     {
         //ui error happened
         return(null);
     }
 }
Пример #3
0
        public IActionResult DeleteMedicineRequest(long id)
        {
            MedicineRequest medicineRequest = MedicineRequest_repo.Find(id);

            if (medicineRequest == null)
            {
                return(NotFound());
            }

            MedicineRequest_repo.Delete(medicineRequest);
            return(Ok());
        }
Пример #4
0
        public IActionResult AddMedicine([FromBody] MedicineRequest medicineData)
        {
            Medicine entity = new Medicine();

            entity.Name       = medicineData.Name;
            entity.Notes      = medicineData.Notes;
            entity.Price      = medicineData.Price;
            entity.Quantity   = medicineData.Quantity;
            entity.Brand      = medicineData.Brand;
            entity.ExpiryDate = medicineData.ExpiryDate;

            _context.medicines.Add(entity);
            _context.SaveChanges();
            return(StatusCode(Convert.ToInt32(HttpStatusCode.Created), medicineData));
        }
Пример #5
0
        public IActionResult UpdateMedicine([FromBody][Required] MedicineRequest medicineData)
        {
            var entity = _context.medicines.ToList().FirstOrDefault(x => x.Id == medicineData.Id);

            if (entity != null)
            {
                entity.Name     = medicineData.Name;
                entity.Notes    = medicineData.Notes;
                entity.Price    = medicineData.Price;
                entity.Quantity = medicineData.Quantity;
                _context.medicines.Update(entity);
                _context.SaveChanges();
                return(StatusCode(Convert.ToInt32(HttpStatusCode.OK), medicineData));
            }
            return(Ok("Entity Not found"));
        }
Пример #6
0
        /// <summary>
        /// Validate request
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        public void Validate(MedicineRequest request, out MedicineResponse response)
        {
            response = new MedicineResponse();

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

                if (request.Data.Name == null || String.IsNullOrWhiteSpace(request.Data.Name))
                {
                    errorFields.Add("Medicine Name");
                }

                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 MedicineHandler(_unitOfWork).CreateOrEdit(request);
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Delete validation
        /// </summary>
        /// <param name="request"></param>
        /// <param name="response"></param>
        private void ValidateForDelete(MedicineRequest request, out MedicineResponse response)
        {
            response = new MedicineResponse();

            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 MedicineHandler(_unitOfWork).RemoveData(request);
            }
        }
Пример #8
0
        public IActionResult CreateMedicineRequest(MedicineRequest mRequest)
        {
            var created = this.storeManager.CreateMedicineRequest(mRequest);

            return(Ok(created));
        }
Пример #9
0
 public IActionResult AddMedicineRequest([FromBody] MedicineRequest model)
 {
     MedicineRequest_repo.Add(model);
     return(new OkObjectResult(new { MedicineRequestID = model.MedicineRequestId }));
 }