Exemplo n.º 1
0
        public IHttpActionResult Create(CreateBranchModel model)
        {
            IHttpActionResult httpActionResult;

            if (string.IsNullOrEmpty(model.Name))
            {
                error.Add("Name is required");
            }
            if (error.errors.Count == 0)
            {
                Branch branch = new Branch();
                branch.BranchCode  = "CN" + RemoveSpacesAndSpecialCharacters.convertToUnSign(model.Name).ToUpper();;
                branch.Name        = model.Name;
                branch.Address     = model.Address;
                branch.PhoneNumber = model.PhoneNumber;
                branch.CreatedDate = DateTime.Now;
                branch.CreatedBy   = User.Identity.Name;

                branch = db.Branches.Add(branch);
                db.SaveChanges();
                httpActionResult = Ok(new BranchModel(branch));
            }
            else
            {
                httpActionResult = new ErrorActionResult(Request, HttpStatusCode.BadRequest, error);
            }
            return(httpActionResult);
        }
Exemplo n.º 2
0
        public IHttpActionResult Create(CreateProductModel model)
        {
            IHttpActionResult httpActionResult;

            if (string.IsNullOrEmpty(model.Name))
            {
                error.Add("Name is required");
            }
            if (error.errors.Count == 0)
            {
                Product product = new Product();
                product.ProductCode    = "SP" + RemoveSpacesAndSpecialCharacters.convertToUnSign(model.Name).ToUpper();
                product.Name           = model.Name;
                product.Price          = model.Price;
                product.PromotionPrice = model.PromotionPrice;
                product.CreatedDate    = DateTime.Now;
                product.CreatedBy      = User.Identity.Name;

                product = db.Products.Add(product);
                db.SaveChanges();
                httpActionResult = Ok(new ProductModel(product));
            }
            else
            {
                httpActionResult = new ErrorActionResult(Request, HttpStatusCode.BadRequest, error);
            }
            return(httpActionResult);
        }
Exemplo n.º 3
0
        public async Task <IHttpActionResult> Create(CreateBillModel model)
        {
            IHttpActionResult httpActionResult;

            if (CheckPhoneNumber.CheckCorrectPhoneNumber(model.BuyerPhone))
            {
                error.Add("Vui lòng nhập đúng sdt!");
                httpActionResult = new ErrorActionResult(Request, HttpStatusCode.BadRequest, error);
            }
            if (error.errors.Count == 0 && CheckPhoneNumber.CheckCorrectPhoneNumber(model.BuyerPhone))
            {
                this._userManager = new ApplicationUserManager(new UserStore <Account>(this.db));

                Bill bill = new Bill();
                bill.BillCode = "HD" + RemoveSpacesAndSpecialCharacters.convertToUnSign(DateTime.Now.Date.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString());
                bill.Account  = await _userManager.FindByNameAsync(User.Identity.Name);

                bill.Branch        = db.Branches.FirstOrDefault(x => x.Id == model.BranchId);
                bill.CreatedDate   = DateTime.Now;
                bill.CreatedBy     = User.Identity.Name;
                bill.BuyerName     = model.BuyerName ?? model.BuyerName;
                bill.BuyerAddress  = model.BuyerAddress ?? model.BuyerAddress;
                bill.BuyerPhone    = model.BuyerPhone ?? model.BuyerPhone;
                bill.ModeOfPayment = model.ModeOfPayment ?? model.ModeOfPayment;
                bill = db.Bills.Add(bill);
                db.SaveChanges();
                httpActionResult = Ok(new BillModel(bill));
            }
            else
            {
                httpActionResult = new ErrorActionResult(Request, HttpStatusCode.BadRequest, error);
            }
            return(httpActionResult);
        }