コード例 #1
0
ファイル: BasketsController.cs プロジェクト: pazka/PAShop.API
        public IActionResult AddItem(Guid itemId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Item item;

            try {
                item = _itemService.GetAll(i => i.Id == itemId).SingleOrDefault();
                Dictionary <StockMovementType, int> stocks = _itemService.GetGlobalQuantity(itemId);
                if (stocks.GetValueOrDefault(StockMovementType.Regular) <= 0)
                {
                    return(Ok(new { text = $"No stock left ( {stocks.GetValueOrDefault(StockMovementType.Reserved)} reserved)." }));
                }
            }
            catch (DbUpdateException e) {
                return(Ok(new { text = "Item not found" }));
            }

            Basket basket = _service.Mine(_httpContextAccessor.HttpContext.User);

            try
            {
                basket.BasketItems.SingleOrDefault(bi => bi.ItemId == itemId).Quantity++;
            }
            catch (Exception)
            {
                basket.BasketItems.Add(new BasketItem()
                {
                    BasketId = basket.Id,
                    ItemId   = item.Id,
                    Quantity = 1
                });
            }

            _stockMovementService.Add(new StockMovement()
            {
                Amount        = 1,
                LastInventory = _inventoryService.Get(i => i.Item.Id == itemId).MaxBy(i => i.Timestamp).SingleOrDefault(),
                Item          = item,
                Timestamp     = DateTime.Now,
                Type          = StockMovementType.Reserved
            });

            _stockMovementService.Add(new StockMovement()
            {
                Amount        = -1,
                LastInventory = _inventoryService.Get(i => i.Item.Id == itemId).MaxBy(i => i.Timestamp).SingleOrDefault(),
                Item          = item,
                Timestamp     = DateTime.Now,
                Type          = StockMovementType.Regular
            });

            _service.Put(basket);

            return(Ok(_service.Mine(_httpContextAccessor.HttpContext.User)));
        }
コード例 #2
0
 public async Task<IActionResult> UpSertProductNumber(int prodId, string[] number)
 {
     var models = await _IProductTransactionService.GetList(x => x.IsActive == 1 && x.MaterialId == prodId);
     models.ToList().ForEach(item =>
     {
         item.IsActive = 0;
         item.IsDeleted = 1;
         item.UpdatedBy = 1;
         item.UpdatedDate = DateTime.Now.Date;
     });
     var response = await _IProductTransactionService.Delete(models.ToArray());
     var prodList = new List<ProductTransactionDetail>();
     for (int i = 0; i < number.Count(); i++)
     {
         ProductTransactionDetail prod = new ProductTransactionDetail()
         {
             ItemNumber = number[i],
             MaterialId = prodId,
             IsActive = 1,
             IsDeleted = 0,
             CreatedBy = 1,
             CreatedDate = DateTime.Now.Date
         };
         prodList.Add(prod);
     }
     var updateResponse = await _IProductTransactionService.Add(prodList.ToArray());
     return Json(ResponseHelper.GetResponseMessage(updateResponse));
 }
コード例 #3
0
        public ActionResult Upload(int id, IEnumerable <HttpPostedFileBase> fileUpload)
        {
            //string idstr = Request.Params["id"];
            //int id = Convert.ToInt32(idstr);
            foreach (var file in fileUpload)
            {
                if (file == null)
                {
                    continue;
                }
                string path     = AppDomain.CurrentDomain.BaseDirectory + "Files/";
                string filename = Path.GetFileName(file.FileName);

                if (filename != null)
                {
                    //1. Получаем расширение
                    string ext = Path.GetExtension(filename);
                    //2. Генерируем уникальный ключ...
                    var partname = Guid.NewGuid().ToString() + ext;
                    file.SaveAs(Path.Combine(path, partname));
                    PhotoDTO photo = new PhotoDTO
                    {
                        GoodId    = id,
                        PhotoPath = "/Files/" + partname
                    };
                    photoService.Add(photo);
                }
            }

            return(RedirectToAction("PhotoList", new { id = id }));
        }
コード例 #4
0
        public async Task <IActionResult> Upload(UploadFile model)
        {
            var fileEntry = new FileEntry
            {
                Name         = model.Name,
                Description  = model.Description,
                Size         = model.FormFile.Length,
                UploadedTime = DateTime.Now,
                FileName     = model.FormFile.FileName,
            };

            _fileEntryService.Add(fileEntry);

            using (var stream = new MemoryStream())
            {
                await model.FormFile.CopyToAsync(stream);

                _fileManager.Create(fileEntry, stream);
            }

            _fileEntryService.Update(fileEntry);

            _fileUploadedEventSender.Send(new FileUploadedEvent
            {
                FileEntry = fileEntry,
            });

            return(View());
        }
        public virtual async Task <IHttpActionResult> Post([FromBody] E entity)
        {
            AuditorService.Audit(entity, Request);
            var postedEntity = service.Add(entity);

            return(await Task.FromResult(Ok <E>(postedEntity)));
        }
コード例 #6
0
        public ActionResult Upload(IEnumerable <HttpPostedFileBase> fileUploadMulti)//fileUploadMulti обязательно совпадет с input
        {
            string idstr = Request.Params["id"];
            int    id    = Convert.ToInt32(idstr);

            foreach (var file in fileUploadMulti)
            {
                if (file == null)
                {
                    continue;
                }
                string path        = AppDomain.CurrentDomain.BaseDirectory + "img/";
                string filename    = Path.GetFileName(file.FileName);
                string newfilename = Guid.NewGuid().ToString() + Path.GetExtension(filename);
                if (filename != null)
                {
                    file.SaveAs(Path.Combine(path, newfilename));
                    PhotoDTO photo = new PhotoDTO
                    {
                        ProductId = id,
                        PhotoPath = "/img/" + newfilename
                    };
                    servicePhoto.Add(photo);
                }
            }
            return(RedirectToAction("Index", new { id = id }));
        }
コード例 #7
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!Helper.HasWriteAccess(ApplicationFroms.frmAddCompany))
            {
                return;
            }

            if (txtCompanyName.Text == "")
            {
                Helper.ShowMessage("Please specify a company name", "Company Name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (cmbLocation.SelectedIndex == -1)
            {
                Helper.ShowMessage("Please select your default location", "Select Default Location", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            Company company = new Company();

            company.Address1        = txtAddress.Text;
            company.Address2        = txtAddress2.Text;
            company.Address3        = txtAddress3.Text;
            company.CompanyName     = txtCompanyName.Text;
            company.Email           = txtEmail.Text;
            company.FaxNumber       = txtFax.Text;
            company.Location        = txtLocation.Text;
            company.Logo            = pbLogo.Image == null ? null : Helper.ImageToByteArray(pbLogo.Image);
            company.Misc            = txtMisc.Text;
            company.Motto           = txtMotto.Text;
            company.PhoneLine1      = txtPhone.Text;
            company.PhoneLine2      = txtPhone2.Text;
            company.PhoneLine3      = txtPhone3.Text;
            company.WebSite         = txtWebsite.Text;
            company.City            = txtCity.Text;
            company.Country         = txtCountry.Text;
            company.DefaultLocation = cmbLocation.SelectedValue.ToInt();

            try
            {
                if (_companyID == 0)
                {
                    _companyService.Add(company);
                }
                else
                {
                    company.CompanyID = _companyID;
                    _companyService.Update(company, c => c.CompanyID == _companyID);
                }

                this.Close();
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "An error occurred", "frmAddCustomer", "btnSave");
                Helper.ShowMessage("An error occured " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #8
0
 public virtual ActionResult Edit(DTO obj)
 {
     if (ModelState.IsValid)
     {
         service.Add(obj);
         return(RedirectToAction("Index"));
     }
     return(View());
 }
コード例 #9
0
 public ActionResult Create([FromBody] ProductDTO prod)
 {
     if (ModelState.IsValid)
     {
         service.Add(prod);
         return(RedirectToAction("Index"));
     }
     return(View(prod));
 }
コード例 #10
0
 public ActionResult AgregarPregunta(Pregunta model)
 {
     if (ModelState.IsValid)
     {
         _preguntas.Add(model);
         return(RedirectToAction("VerPreguntasJOINS", new { evaluacionId = model.EvaluacionId }));
     }
     return(View(model));
 }
コード例 #11
0
 public ActionResult Edit(StreetDTO obj)
 {
     if (ModelState.IsValid)
     {
         streetService.Add(obj);
         streetService.Save();
         return(RedirectToAction("Index"));
     }
     return(View());
 }
コード例 #12
0
        public IActionResult Post([FromBody] Item obj)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _newService.Add(obj);
            return(Ok(obj));
        }
コード例 #13
0
 public ActionResult Edit(AddressDTO obj)
 {
     if (ModelState.IsValid)
     {
         addressService.Add(obj);
         addressService.Save();
         return(RedirectToAction("Index"));
     }
     return(View());
 }
コード例 #14
0
ファイル: BasketsController.cs プロジェクト: pazka/PAShop.API
        public IActionResult ValidateBasket(Guid basketId)
        {
            User   user   = _userService.Me(_httpContextAccessor.HttpContext.User);
            Basket basket = _service.Get(b => b.Id == basketId && b.State == BasketState.NotValidated).SingleOrDefault();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (basket == null)
            {
                return(BadRequest("Basket not found"));
            }
            else if (basket.Owner.Id != user.Id && user.Role < Role.Admin)
            {
                return(StatusCode(403, "Not your basket and not an Admin."));
            }

            Transaction transaction = new Transaction()
            {
                Order   = basket,
                OrderId = basketId,
                Owner   = user,
                OwnerId = user.Id,
                State   = TransactionState.Payed
            };

            foreach (BasketItem bi in basket.BasketItems)
            {
                _stockMovementService.Add(new StockMovement()
                {
                    Amount        = -bi.Quantity,
                    LastInventory = _inventoryService.Get(i => i.Item.Id == bi.ItemId).MaxBy(i => i.Timestamp).SingleOrDefault(),

                    Item      = bi.Item,
                    Timestamp = DateTime.Now,
                    Type      = StockMovementType.Reserved
                });
            }

            basket.Transaction = transaction;
            basket.State       = BasketState.Payed;

            _transactionService.Add(transaction);
            _service.Put(basket);
            _service.Add(new Basket()
            {
                State = BasketState.NotValidated,
                Owner = user
            });

            return(Ok(_service.Mine(HttpContext.User)));
        }
コード例 #15
0
ファイル: ItemsController.cs プロジェクト: pazka/PAShop.API
        public IActionResult ChangeQuantityDisp([FromRoute] Guid itemId, [FromBody] dynamic body)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (body.amount == null)
            {
                return(BadRequest("body.amount not found"));
            }
            if (body.type == null)
            {
                return(BadRequest("body.type not found"));
            }

            Item item;
            int  amount = body.amount;

            try
            {
                item = _service.GetAll(i => i.Id == itemId).SingleOrDefault();
            }
            catch (DbUpdateException e)
            {
                return(Ok(new { text = "Item not found." + e.ToString() }));
            }

            StockMovement stockMovement = new StockMovement()
            {
                Amount        = amount,
                LastInventory = _inventoryService.Get(i => i.Item.Id == itemId).MaxBy(i => i.Timestamp).SingleOrDefault(),
                Item          = item,
                Timestamp     = DateTime.Now,
                Type          = body.type
            };

            _stockMovementService.Add(stockMovement);

            return(Ok(new{ stock = _itemService.GetGlobalQuantity(itemId), item = _itemService.GetAll(i => i.Id == itemId) }));
        }
コード例 #16
0
 public HttpResponseMessage Post(StreetDTO street)
 {
     try
     {
         streetService.Add(street);
         return(Request.CreateResponse(HttpStatusCode.OK, street));
     }
     catch (Exception exc)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, "Не смогли получить адрес"));
     }
 }
コード例 #17
0
 public HttpResponseMessage Post(SubdivisionDTO address)
 {
     try
     {
         subdivisionService.Add(address);
         return(Request.CreateResponse(HttpStatusCode.OK, address));
     }
     catch (Exception exc)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, "Не смогли получить адрес"));
     }
 }
コード例 #18
0
 public ActionResult <Project> Add([FromBody] ProjectDTO project)
 {
     try
     {
         return(Ok(_service.Add(project)));
     }
     catch (Exception e)
     {
         Log.Error(e.ToString());
         return(Redirect("/error"));
     }
 }
コード例 #19
0
 public int Add(Game game)
 {
     try
     {
         gameRepo.Add(game);
         gameRepo.Save();
     }
     catch (Exception ex)
     {
         string error = ex.Message;
     }
     return(game.Id);
 }
コード例 #20
0
 public int Add(GameUser obj)
 {
     try
     {
         gameUserRepo.Add(obj);
         gameUserRepo.Save();
     }
     catch (Exception ex)
     {
         string error = ex.Message;
     }
     return(obj.Id);
 }
コード例 #21
0
 public int Add(Answer answer)
 {
     try
     {
         answerRepo.Add(answer);
         answerRepo.Save();
     }
     catch (Exception ex)
     {
         string error = ex.Message;
     }
     return(answer.Id);
 }
コード例 #22
0
 public int Add(QuizCategory quizCategory)
 {
     try
     {
         offerRepo.Add(quizCategory);
         offerRepo.Save();
     }
     catch (Exception ex)
     {
         string error = ex.Message;
     }
     return(quizCategory.Id);
 }
コード例 #23
0
 public int Add(Question question)
 {
     try
     {
         questionRepo.Add(question);
         questionRepo.Save();
     }
     catch (Exception ex)
     {
         string error = ex.Message;
     }
     return(question.Id);
 }
コード例 #24
0
 public int Add(QuizOffer quizOffer)
 {
     try
     {
         offerRepo.Add(quizOffer);
         offerRepo.Save();
     }
     catch (Exception ex)
     {
         string error = ex.Message;
     }
     return(quizOffer.Id);
 }
コード例 #25
0
 public int Add(QuizHistory quizHistory)
 {
     try
     {
         quizHistoryRepo.Add(quizHistory);
         quizHistoryRepo.Save();
     }
     catch (Exception ex)
     {
         string error = ex.Message;
     }
     return(quizHistory.Id);
 }
コード例 #26
0
 public int Add(Icon icon)
 {
     try
     {
         iconRepo.Add(icon);
         iconRepo.Save();
     }
     catch (Exception ex)
     {
         string error = ex.Message;
     }
     return(icon.Id);
 }
コード例 #27
0
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByNameAsync(model.UserName);

                if (user == null)
                {
                    user = new User
                    {
                        UserName = model.UserName,
                        Email    = model.UserName
                    };

                    var result = await _userManager.CreateAsync(user, model.Password);

                    if (result.Succeeded)
                    {
                        var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                        var confirmationEmail = Url.Action("ConfirmEmailAddress", "Account",
                                                           new { token = token, email = user.Email }, Request.Scheme);

                        _emailMessageService.Add(new EmailMessage
                        {
                            From    = "",
                            To      = user.Email,
                            Subject = "Confirmation Email",
                            Body    = string.Format("Confirmation Email: {0}", confirmationEmail)
                        });
                    }
                }

                return(View("Success"));
            }

            return(View());
        }
コード例 #28
0
ファイル: StepSaveModel.cs プロジェクト: ANG78/ReactExamples
        protected override IResult ExecuteTemplate(IManagementModelRequest <T> obj)
        {
            if (obj.Type == EnumOperation.NEW)
            {
                return(_service.Add(obj.Item));
            }
            else if (obj.Type == EnumOperation.EDITION)
            {
                return(_service.Edit(obj.Item));
            }


            return(Result.Ok);
        }
コード例 #29
0
ファイル: CategoryController.cs プロジェクト: ViktorDem/Shop
 public HttpResponseMessage Post(CategoryDTO category)
 {
     try
     {
         var c = categoryService.Add(category);
         HttpResponseMessage message = Request.CreateResponse(HttpStatusCode.Created, c);
         message.Headers.Add("CategoryId", c.CategoryId.ToString());
         return(message);
     }
     catch (Exception exc)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, "Не смогли добавить категорию"));
     }
 }
コード例 #30
0
ファイル: GoodsController.cs プロジェクト: ViktorDem/Shop
 public HttpResponseMessage Post(GoodDTO good)
 {
     try
     {
         var g = goodService.Add(good);
         HttpResponseMessage message = Request.CreateResponse(HttpStatusCode.Accepted, g);
         message.Headers.Add("GoodId", g.GoodId.ToString());
         return(message);
     }
     catch (Exception exc)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, "Не смогли добавить категорию"));
     }
 }