Esempio n. 1
0
        public RequestedItemViewModel UpdateRequestedItem([FromBody] RequestedItemViewModel requestedItemViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var requestedItem = this._requestedItemService.UpdateRequestedItem(requestedItemViewModel);

                    return(requestedItem);
                }
                else
                {
                    var    errors       = ModelState.Values.SelectMany(e => e.Errors).Select(e => e.ErrorMessage);
                    string generalError = string.Join(" ", errors);

                    return(new RequestedItemViewModel
                    {
                        ErrorMessage = generalError
                    });
                }
            }
            catch (Exception ex)
            {
                return(new RequestedItemViewModel
                {
                    ErrorMessage = ex.Message
                });
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates requested item in database
        /// </summary>
        /// <param name="requestedItemViewModel">Requested item view model</param>
        /// <returns>Requested item view model</returns>
        public RequestedItemViewModel CreateRequestedItem(RequestedItemViewModel requestedItemViewModel)
        {
            const string InitialStatusName = StuffStatus.New;

            try
            {
                if (requestedItemViewModel == null)
                {
                    throw new ArgumentNullException(nameof(requestedItemViewModel));
                }

                Status status = this._unitOfWork.StatusRepository.GetStatusByName(InitialStatusName);

                if (status == null)
                {
                    throw new BusinessLogicException($"Статус {InitialStatusName} не знайдено");
                }

                RequestedItem requestedItem = this.convertRequestedItem(requestedItemViewModel);
                requestedItem = this._unitOfWork.RequestedItemRepository.Create(requestedItem);
                var requestedImagesList = this.convertViewModelImageList(requestedItemViewModel.Images,
                                                                         requestedItem.Id);
                this._unitOfWork.RequestedItemImageRepository.SaveListOfImages(requestedImagesList);
                this._unitOfWork.SaveChanges();

                return(requestedItemViewModel);
            }
            catch (Exception ex)
            {
                string message = string.Format("Потреба не була створена. Помилка: {0}", ex.Message);
                throw new BusinessLogicException(message, ex);
            }
        }
 public RequestedItemViewModel AddRequestedItem([FromBody] RequestedItemViewModel requestedItemViewModel)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var a = HttpContext.Items;
             return(this._requestedItemService.CreateRequestedItem(requestedItemViewModel));
             //return requestedItemViewModel;
         }
         else
         {
             var    errors       = ModelState.Values.SelectMany(e => e.Errors).Select(e => e.ErrorMessage);
             string generalError = string.Join(" ", errors);
             return(new RequestedItemViewModel
             {
                 ErrorMessage = generalError
             });
         }
     }
     catch (Exception ex)
     {
         return(new RequestedItemViewModel
         {
             ErrorMessage = ex.Message
         });
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Creates requested item in database
        /// </summary>
        /// <param name="requestedItemViewModel">Requested item view model</param>
        /// <returns>Requested item view model</returns>
        public RequestedItemViewModel CreateRequestedItem(RequestedItemViewModel requestedItemViewModel)
        {
            const string InitialStatusName = StuffStatus.New;

            try
            {
                if (requestedItemViewModel == null)
                {
                    throw new ArgumentNullException(nameof(requestedItemViewModel));
                }

                Status status = this._unitOfWork.StatusRepository.GetStatusByName(InitialStatusName);

                if (status == null)
                {
                    throw new BusinessLogicException($"{ErrorMessages.StatusWasnotFound} {InitialStatusName}");
                }

                RequestedItem requestedItem = this.convertRequestedItem(requestedItemViewModel);
                requestedItem = this._unitOfWork.RequestedItemRepository.Create(requestedItem);
                var requestedImagesList = this.UploadImagesToStorage(requestedItemViewModel.Images,
                                                                     requestedItem.Id);
                this._unitOfWork.RequestedItemImageRepository.SaveListOfImages(requestedImagesList);
                this._unitOfWork.SaveChanges();

                return(requestedItemViewModel);
            }
            catch (Exception ex)
            {
                string message = $"{ErrorMessages.RequstWasnotCreated} {ErrorMessages.Error} { ex.Message}";
                throw new BusinessLogicException(message, ex);
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Converts requested item
 /// </summary>
 /// <param name="requestedItemViewModel"></param>
 /// <returns>Requested item view model</returns>
 private RequestedItem convertRequestedItem(RequestedItemViewModel requestedItemViewModel)
 {
     return(new RequestedItem
     {
         Id = requestedItemViewModel.Id,
         Name = requestedItemViewModel.Name,
         Description = requestedItemViewModel.Description,
         StatusId = 1,
         OrganizationId = requestedItemViewModel.OrganizationId,
         GoodsCategoryId = requestedItemViewModel.GoodsCategoryId
     });
 }
Esempio n. 6
0
        public RequestedItemViewModel GetRequestedItem(int id)
        {
            try
            {
                RequestedItemViewModel requestedItemViewModel = this._requestedItemService.GetItemById(id);

                return(requestedItemViewModel);
            }
            catch (Exception ex)
            {
                return(new RequestedItemViewModel()
                {
                    ErrorMessage = ex.Message
                });
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Updates requested item in database
        /// </summary>
        /// <param name="requestedItemViewModel">Requested item view model</param>
        /// <returns>Requested item view model</returns>
        public RequestedItemViewModel UpdateRequestedItem(RequestedItemViewModel requestedItemViewModel)
        {
            try
            {
                RequestedItem requestedItem = this.convertRequestedItem(requestedItemViewModel);
                SetRequestedItemImage(requestedItemViewModel.Images, requestedItem);

                this._unitOfWork.RequestedItemRepository.Update(requestedItem);
                this._unitOfWork.SaveChanges();

                return(requestedItemViewModel);
            }
            catch (Exception ex)
            {
                throw new BusinessLogicException(ex.Message);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Updates requested item in database
        /// </summary>
        /// <param name="requestedItemViewModel">Requested item view model</param>
        /// <returns>Requested item view model</returns>
        public RequestedItemViewModel UpdateRequestedItem(RequestedItemViewModel requestedItemViewModel)
        {
            var imagesToUpdate = requestedItemViewModel.Images.Where(e => e.RequestedItemId == 0);
            IEnumerable <RequestedItemImage> imagesList = this.convertViewModelImageList(imagesToUpdate,
                                                                                         requestedItemViewModel.Id);

            try
            {
                RequestedItem requestedItem = this.convertRequestedItem(requestedItemViewModel);

                this._unitOfWork.RequestedItemRepository.Update(requestedItem);
                this._unitOfWork.RequestedItemImageRepository.SaveListOfImages(imagesList);

                this._unitOfWork.SaveChanges();

                return(requestedItemViewModel);
            }
            catch (Exception ex)
            {
                throw new BusinessLogicException(ex.Message);
            }
        }
        // GET: ManageRequest
        public ActionResult Index()
        {
            List <RequestedItemViewModel> models = new List <RequestedItemViewModel>();

            ViewBag.ShowItems = false;
            LogicDB context = new LogicDB();
            string  userId  = User.Identity.GetUserId();
            string  depId   = context.AspNetUsers.FirstOrDefault(x => x.Id == userId).DepartmentId;


            List <StationeryRequest> requests = context.StationeryRequest.Where(x => x.Status == "Pending Approval" && x.DepartmentId == depId).ToList();

            if (requests.Count > 0)
            {
                ViewBag.ShowItems = true;

                foreach (var c in requests)
                {
                    RequestedItemViewModel reqItem = new RequestedItemViewModel();
                    reqItem.RequestDate = String.Format("{0:dd/MM/yyyy}", c.RequestDate);
                    AspNetUsers emp = context.AspNetUsers.FirstOrDefault(x => x.Id == c.RequestedBy);
                    reqItem.Empname = emp.EmployeeName;
                    var requestId = c.RequestId;
                    reqItem.RequestID = c.RequestId;
                    List <TransactionDetail> transactionDetails = context.TransactionDetail.Where(x => x.TransactionRef == requestId).ToList();
                    List <Stationery>        items = new List <Stationery>();
                    foreach (var i in transactionDetails)
                    {
                        Stationery item = context.Stationery.FirstOrDefault(x => x.ItemId == i.ItemId);
                        item.QuantityTransit = i.Quantity;
                        items.Add(item);
                    }
                    reqItem.Itemlist = items;
                    models.Add(reqItem);
                }
            }
            return(View(models));
        }
Esempio n. 10
0
        /// <summary>
        /// Gets requested item from database
        /// </summary>
        /// <param name="id">Id of requested item</param>
        /// <returns>Requested item view model</returns>
        public RequestedItemViewModel GetItemById(int id)
        {
            try
            {
                RequestedItem requestedItem = this._unitOfWork.RequestedItemRepository.Get(id);

                if (requestedItem == null)
                {
                    throw new BusinessLogicException($"Потреба з ідентифікатором {id} не знайдена");
                }

                IEnumerable <RequestedImageViewModel> imagesList = this.convertRequestItemImageModelList(requestedItem.RequestedItemImages,
                                                                                                         requestedItem.Id);

                RequestedItemViewModel itemViewModel = this.convertToRequestedItemViewModel(requestedItem, imagesList);

                return(itemViewModel);
            }
            catch (Exception ex)
            {
                throw new BusinessLogicException(ex.Message);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Gets requested item from database
        /// </summary>
        /// <param name="id">Id of requested item</param>
        /// <returns>Requested item view model</returns>
        public RequestedItemViewModel GetItemById(int id)
        {
            try
            {
                RequestedItem requestedItem = this._unitOfWork.RequestedItemRepository.Get(id);

                if (requestedItem == null)
                {
                    throw new BusinessLogicException($"{ErrorMessages.RequstWasnotFoundWithId} {id} ");
                }

                IEnumerable <RequestedImageViewModel> imagesList = this.convertRequestItemImageModelList(requestedItem.RequestedItemImages,
                                                                                                         requestedItem.Id);

                RequestedItemViewModel itemViewModel = this.convertToRequestedItemViewModel(requestedItem, imagesList);

                return(itemViewModel);
            }
            catch (Exception ex)
            {
                throw new BusinessLogicException(ex.Message);
            }
        }