Example #1
0
        public void Update(ItemDetailModel itemDetail)
        {
            using (var context = new PhotoLibraryDbContext())
            {
                var itemEntity = context.Items.First(a => a.Id == itemDetail.Id);

                itemEntity.Name = itemDetail.Name;

                context.SaveChanges();
            }
        }
Example #2
0
 public async Task <IActionResult> SearchAllItems([FromBody] ItemDetailModel model)
 {
     try
     {
         dynamic response = await new ItemManager().SearchAllItems(model);
         return(Ok(response));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Example #3
0
 public Item DetailModelToEntity(ItemDetailModel item)
 {
     if (item == null)
     {
         return(null);
     }
     return(new Item()
     {
         Id = item.Id,
         Name = item.Name
     });
 }
Example #4
0
        public async void Get_Item()
        {
            var mockItemService = new Mock <IItemService>();

            mockItemService.Setup(x => x.Get <ItemDetailModel>(It.IsAny <int>())).ReturnsAsync(new ItemDetailModel());

            IMapper     mapper  = TestUtilities.GetMapper(new ItemProfile());
            ItemManager manager = new ItemManager(_logger, mapper, mockItemService.Object);

            ItemDetailModel model = await manager.Get(1);

            Assert.NotNull(model);
        }
Example #5
0
        public ItemDetailModel Insert(ItemDetailModel itemDetail, Guid photoId)
        {
            using (var context = new PhotoLibraryDbContext())
            {
                var itemEntity = mapper.DetailModelToEntity(itemDetail);
                itemEntity.Id = Guid.NewGuid();
                itemEntity.Photos.Add(context.Photos.First(a => a.Id == photoId));

                context.Items.Add(itemEntity);
                context.SaveChanges();

                return(mapper.EntityToDetailModel(itemEntity));
            }
        }
Example #6
0
        public async Task <ApplicationResult> Edit(ItemDetailModel model)
        {
            ItemDetailModelValidator validator = new ItemDetailModelValidator();
            ValidationResult         result    = await validator.ValidateAsync(model);

            if (result.IsValid)
            {
                Item item = _mapper.Map <Item>(model);
                int  id   = await _service.Update(item);

                return(ApplicationResult.Success("Item updated", id));
            }
            return(ApplicationResult.Error(result));
        }
Example #7
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var item = _context.ItemDetails.Where(e => e.Id == id).FirstOrDefault();

            if (item == null)
            {
                return(NotFound());
            }
            Input = new ItemDtoMap().Map(item);
            return(Page());
        }
Example #8
0
        public ItemSingleModel GetItemById(int id)
        {
            ItemSingleModel        result             = new ItemSingleModel();
            ItemDetailModel        singleItemDetail   = new ItemDetailModel();
            List <ItemDetailModel> completeItemDetail = new List <ItemDetailModel>();

            var query           = _itemDataAccess.GetItemById(id);
            var itemDetailQuery = _itemDataAccess.GetItemDetailByItemId(query.Id);
            var uom             = _itemDataAccess.GetItemUnitsOfMeasure(itemDetailQuery);

            result.Id                  = query.Id;
            result.ItemName            = query.ItemName;
            result.CategoryId          = query.CategoryID;
            result.SubCategoryId       = query.SubCategoryID;
            result.BrandName           = query.Brand.BrandName;
            result.LocationId          = query.LocationID;
            result.Quantity            = query.Quantity.HasValue ? query.Quantity.Value : 0;
            result.ThresholdQty        = query.ThresholdQty.HasValue ? query.ThresholdQty.Value : 0;
            result.WarningThresholdQty = query.WarningThresholdQty.HasValue ? query.WarningThresholdQty.Value : 0;
            result.MeasuredBy          = query.MeasuredBy;
            result.Sku                 = query.Sku;
            result.Notes               = query.Notes;
            result.StatusCd            = query.CodeDetail.CodeValue;
            result.CreateUserName      = query.CreateUserName;
            result.CreateDttm          = query.CreateDttm;
            result.UpdateUserName      = query.UpdateUserName;
            result.UpdateDttm          = query.UpdateDttm;
            result.UnitPrice           = query.UnitPrice.HasValue ? query.UnitPrice.Value : 0.00m;
            result.RetailPrice         = query.RetailPrice.HasValue ? query.RetailPrice.Value : 0.00m;

            for (int i = 0; i < itemDetailQuery.Count; i++)
            {
                singleItemDetail.Id                 = itemDetailQuery[i].Id;
                singleItemDetail.ItemDetailId       = itemDetailQuery[i].ItemDetail.Id;
                singleItemDetail.ShowUnitsOfMeasure = itemDetailQuery[i].ItemDetail.ShowUnitsOfMeasure;
                singleItemDetail.ItemDetailName     = itemDetailQuery[i].ItemDetail.ItemDetailName;
                singleItemDetail.ItemDetailValue    = itemDetailQuery[i].ItemDetailValue;
                singleItemDetail.UnitOfMeasure      = uom.Where(x => x.Id == itemDetailQuery[i].ItemDetail.UnitsOfMeasureID)
                                                      .Select(x => x.UnitOfMeasure).FirstOrDefault();

                completeItemDetail.Add(singleItemDetail);
                singleItemDetail = new ItemDetailModel();
            }

            result.ItemDetail = completeItemDetail;

            return(result);
        }
Example #9
0
 public async Task <IActionResult> SearchItemsWithPagination([FromBody] ItemDetailModel model)
 {
     try
     {
         if (string.IsNullOrEmpty(model.pageno.ToString()) && string.IsNullOrEmpty(model.pagesize.ToString()))
         {
             string msg = "pageNo & pageSize should not be null or empty";
             return(BadRequest(msg));
         }
         dynamic response = await new ItemManager().SearchItemsWithPagination(model);
         return(Ok(response));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Example #10
0
 public async Task <IActionResult> GetItem([FromBody] ItemDetailModel model)
 {
     try
     {
         if (string.IsNullOrEmpty(model.itemId))
         {
             string msg = "itemId should not be null or empty";
             return(BadRequest(msg));
         }
         dynamic response = await new ItemManager().GetItemDetails(model);
         return(Ok(response));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Example #11
0
        public async void Edit_Item_Invalid_MinGreaterThanMax(ItemDetailModel model)
        {
            var mockItemService = new Mock <IItemService>();

            mockItemService.Setup(x => x.Update(It.IsAny <Item>())).ReturnsAsync(1);

            IMapper     mapper  = TestUtilities.GetMapper(new ItemProfile());
            ItemManager manager = new ItemManager(_logger, mapper, mockItemService.Object);

            model.DefaultMinQuantity = 10;
            model.DefaultMaxQuantity = 5;

            ApplicationResult result = await manager.Edit(model);

            _output.WriteLine(result.Message);
            CustomAssertions.AssertValidationErrorsExist(result);
        }
Example #12
0
        // GET: Item
        public ActionResult Detail(string linkName)
        {
            var item = _context.Items.SingleOrDefault(i => i.LinkName == linkName);

            if (item == null)
            {
                return(View("Detail"));
            }

            var itemDetailModel = new ItemDetailModel();

            itemDetailModel.Item = item;
            itemDetailModel.ItemSpecifications      = getItemSpecificationsModel(item);
            itemDetailModel.ItemSpecificationGroups = getItemSpecificationGroups(itemDetailModel.ItemSpecifications);

            itemDetailModel.Reviews = _context.ItemReviews
                                      .Where(ir => ir.ItemId == item.Id)
                                      .Include(ir => ir.Customer)
                                      .Include(ir => ir.Customer.ApplicationUser)
                                      .OrderBy(ir => ir.Date)
                                      .ToArray();

            itemDetailModel.Features = _context.ItemFeatures
                                       .Where(i => i.ItemId == item.Id)
                                       .ToArray();

            var starInfos = new List <StarInfo>();

            for (int i = 1; i < 6; i++)
            {
                var starInfo = new StarInfo();
                starInfo.Value = i;
                starInfo.Count = itemDetailModel.Reviews.Count(r => r.Note == i);
                starInfo.Ratio = itemDetailModel.Reviews.Count() > 0 ? (decimal)starInfo.Count / itemDetailModel.Reviews.Count() : 0;
                starInfos.Add(starInfo);
            }
            itemDetailModel.Stars      = starInfos.ToArray();
            itemDetailModel.OtherItems = _context.ItemLinks
                                         .Where(i => i.MainItemId == item.Id)
                                         .Include(i => i.OtherItem)
                                         .Select(i => i.OtherItem)
                                         .ToArray();

            return(View("Detail", itemDetailModel));
        }
Example #13
0
 public ItemDetail Map(ItemDetailModel itemDetailModel)
 {
     try
     {
         var itemDetail = new ItemDetail();
         itemDetail.Id        = itemDetailModel.Id;
         itemDetail.Name      = itemDetailModel.Name;
         itemDetail.Sku       = itemDetailModel.Sku;
         itemDetail.Price     = itemDetailModel.Price;
         itemDetail.Qty       = itemDetailModel.Qty;
         itemDetail.IsDeleted = itemDetailModel.IsDeleted;
         return(itemDetail);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #14
0
        public List <ItemDetailModel> GetItemDetailBySubCategoryId(int Id)
        {
            ItemDetailModel        singleItem = new ItemDetailModel();
            List <ItemDetailModel> result     = new List <ItemDetailModel>();

            var query = _itemDataAccess.GetItemDetailBySubCategoryId(Id);

            for (int i = 0; i < query.Count; i++)
            {
                singleItem.ItemDetailId       = query[i].Id;
                singleItem.ItemDetailName     = query[i].ItemDetailName;
                singleItem.ShowUnitsOfMeasure = query[i].ShowUnitsOfMeasure;
                singleItem.UnitOfMeasure      = query[i].UnitsOfMeasure.UnitOfMeasure;

                result.Add(singleItem);
                singleItem = new ItemDetailModel();
            }

            return(result);
        }
        [ProducesResponseType(typeof(ItemDetailModel), 200)] // not all fields
        public async Task <IActionResult> GetItemDetail(Guid itemDetailId)
        {
            ItemDetailModel result = await context.ItemDetail
                                     .Where(x => x.ItemDetailId == itemDetailId)
                                     .Select(x => new ItemDetailModel
            {
                itemDetailId   = x.ItemDetailId,
                itemId         = x.ItemId,
                itemName       = null,
                sizeId         = x.SizeId,
                sizeName       = null,
                colorId        = x.ColorId,
                colorName      = null,
                quantity       = x.Quantity,
                itemActionId   = x.ItemActionId,
                itemActionName = null,
                customerId     = x.CustomerId,
                customerEmail  = null
            })
                                     .FirstOrDefaultAsync();

            return(Ok(result));
        }
        public async Task <IActionResult> InsertItemDetail(Guid employeeId, [FromBody] ItemDetailModel itemDetail)
        {
            #region serverside validation

            if (itemDetail.quantity > 1000000000 || itemDetail.quantity < -1000000000)
            {
                return(BadRequest("Quantity must fall within range between minus billion and plus billion"));
            }

            #endregion

            ItemDetail newItemDetail = new ItemDetail();
            try
            {
                // newItemDetail.ItemDetailId will be generated by default
                newItemDetail.ItemId  = itemDetail.itemId;                                                                                                    // not null
                newItemDetail.SizeId  = itemDetail.sizeId;                                                                                                    // not null
                newItemDetail.ColorId = itemDetail.colorId;                                                                                                   // not null
                // if Sold (2) or Lost (6) then quantity is negative
                newItemDetail.Quantity     = (itemDetail.itemActionId == 2 || itemDetail.itemActionId == 6)? (-1) * itemDetail.quantity: itemDetail.quantity; // not null
                newItemDetail.ItemActionId = itemDetail.itemActionId;                                                                                         // not null
                // if Sold (2) or Returned (3) then add CustomerId
                newItemDetail.CustomerId = (itemDetail.itemActionId == 2 || itemDetail.itemActionId == 3) ? itemDetail.customerId : null;
                context.ItemDetail.Add(newItemDetail);
                await context.SaveChangesAsync();

                #region AdminLog

                AdminLog adminLog = new AdminLog();
                adminLog.TableName        = "ItemDetail";
                adminLog.FieldName        = "ItemDetailId";
                adminLog.FieldValue       = newItemDetail.ItemDetailId.ToString();
                adminLog.AdminLogActionId = (int)AdminLogActionEnum.Create;
                adminLog.Notes            = null;
                adminLog.EmployeeId       = employeeId;
                adminLog.Timestamp        = DateTime.Now;
                analyticsRepo.InsertAdminLog(adminLog);

                #endregion

                return(Ok(newItemDetail.ItemDetailId));
            }
            catch (Exception ex)
            {
                #region ErrorLog

                ErrorLog errorLog = new ErrorLog();
                errorLog.Namespace       = "PapaJohnsCloneApi.Controllers";
                errorLog.Class           = "AnalyticsController";
                errorLog.Method          = "InsertItemDetail";
                errorLog.MethodParams    = "(Guid employeeId, [FromBody] ItemDetailModel itemDetail)";
                errorLog.ErrorLogTypeId  = (int)ErrorLogTypeEnum.Error;
                errorLog.ShortComment    = "Failed to insert into ItemDetail";
                errorLog.DetailedComment = ex.InnerException.Message;
                errorLog.Exception       = XmlManipulation.ConvertObjectToXml <Exception>(ex.InnerException);
                errorLog.EmployeeId      = employeeId;
                errorLog.Timestamp       = DateTime.Now;
                // clean Exception before saving AdminLog in db
                context.Entry(newItemDetail).State = EntityState.Detached;
                analyticsRepo.InsertErrorLog(errorLog);

                #endregion
                return(BadRequest());
            }
        }