Esempio n. 1
0
        public Sale Convert(SaleEntity source)
        {
            if (source == null)
            {
                return(null);
            }

            var partitionKey = source.PartitionKey.Split('_');

            if (partitionKey.Length != 2 || !long.TryParse(partitionKey[1], out long isbn) ||
                !DateTime.TryParse(source.RowKey, out DateTime date))
            {
                return(null);
            }


            var result = new Sale
            {
                ISBN   = isbn,
                Date   = date.ToUniversalTime(),
                Seller = source.Seller
            };

            return(result);
        }
        private SaleEntity ReadSaleInternal(string command, object param = null)
        {
            using (IGridReader reader = QueryMultiple(command, param))
            {
                SaleEntity sale = reader.Read <SaleEntity, ShippingEntity, AddressEntity, SaleEntity>((s, sh, a) =>
                {
                    s.Delivery = new Delivery();

                    if (sh != null)
                    {
                        s.Delivery.Shipping = sh;
                    }
                    else
                    {
                        s.Delivery.DeliveryType = DeliveryType.PickUpOnly;
                    }

                    s.Delivery.DeliveryAddress = a;

                    return(s);
                }, splitOn: "ShippingId,AddressId").First();

                sale.Items = reader.Read <SaleItemEntity>().ToList();

                return(sale);
            }
        }
        public async Task <IHttpActionResult> PutSaleEntity(int id, SaleEntity saleEntity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != saleEntity.SaleEntityID)
            {
                return(BadRequest());
            }

            db.Entry(saleEntity).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SaleEntityExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            string                saleId               = textBox1_XSDID.Text;
            string                commodityName        = comboBox1_SPMC.Text;
            string                saleDate             = dateTimePicker1.Text;
            string                str                  = textBox4_XSSL.Text;
            int                   saleNumber           = int.Parse(str);
            string                payMethod            = comboBox2_ZFFS.Text;
            string                workerName           = comboBox1.Text;
            string                Gonghao              = textBox7_GH.Text;
            SaleEntity            entity               = new SaleEntity(saleId, commodityName, saleDate, saleNumber, payMethod, workerName, Gonghao);
            ISaleManageController saleManageController = new SaleManageControllerImpl();

            bool term = saleManageController.InsertSaleInfo(entity);

            if (term == true)
            {
                SalerManage form = new SalerManage();
                MessageBox.Show("添加库存信息成功");
                this.DialogResult = DialogResult.OK;
                this.Hide();
            }
            else
            {
                MessageBox.Show("添加库存信息失败!");
            }
        }
Esempio n. 5
0
 public static SaleInfo SaleEntityToSaleInfo(this SaleEntity entity) =>
 new SaleInfo()
 {
     Id         = entity.Id,
     CreateDate = entity.CreateDate,
     Client     = entity.Client.ClientEntityToClient()
 };
Esempio n. 6
0
    public async Task <ApiError> InsertAsync(SaleModel model)
    {
        var checkresult = await ValidateModelAsync(model);

        if (!checkresult.Successful)
        {
            return(checkresult);
        }
        SaleEntity entity = model !;

        try
        {
            var result = await _saleRepository.InsertAsync(entity);

            if (result.Successful)
            {
                model.Id = entity.Id;
            }
            return(ApiError.FromDalResult(result));
        }
        catch (Exception ex)
        {
            return(ApiError.FromException(ex));
        }
    }
Esempio n. 7
0
        public bool UpdateInfo(SaleEntity obj, string jobnumber)
        {
            con = Connectionsql.Connection();
            bool term = SelectMysql.result("update tb_sale set saleId='" + obj.SalesrecordsId + "'," +
                                           "commodityName='" + obj.Productname + "',saleDate='" + obj.Saledate + "',saleNumber='" + obj.Salenumber + "',payMethod=" +
                                           "'" + obj.Paymethod + "',workerName='" + obj.Workername + "'" +
                                           ",Gonghao='" + obj.Jobnumber + "' where saleId='" + jobnumber + "'");

            try
            {
                if (term == true)
                {
                    return(term);
                }
            }
            catch (MySqlException e)
            {
                MessageBox.Show(e.Message, "提示", MessageBoxButtons.OK);
            }
            finally
            {
                con.Close();
            }

            return(term);
        }
Esempio n. 8
0
        public async Task <IHttpActionResult> GetSaleEntity(int GoodID, int SaleID)
        {
            SaleEntity saleEntity = await db.SaleEntities.FindAsync(SaleID);

            GoodEntity goodEntity = await db.GoodEntities.FindAsync(GoodID);

            Dictionary <string, object> dict = new Dictionary <string, object>();
            HttpResponseMessage         resp;

            if (saleEntity == null || goodEntity == null)
            {
                if (saleEntity == null)
                {
                    dict.Add("error", "SaleEntity " + SaleID + " not exists");
                }
                else
                {
                    dict.Add("error", "GoodEntity " + GoodID + " not exists");
                }
                resp = Request.CreateResponse(HttpStatusCode.NotFound, dict);
            }
            else
            {
                dict.Add("SaleEntity", saleEntity);
                resp = Request.CreateResponse(HttpStatusCode.OK, dict);
            }

            return(ResponseMessage(resp));
        }
Esempio n. 9
0
        public bool InsertInfo(SaleEntity obj)
        {
            con = Connectionsql.Connection();
            bool term = SelectMysql.result("insert into  tb_sale(saleId,commodityName,saleDate,saleNumber,payMethod,workerName" +
                                           ",Gonghao) values(" + "'" + obj.SalesrecordsId + "'" + "," + "'" + obj.Productname + "'" + ","
                                           + "'" + obj.Saledate + "'" + "," + "'" + obj.Salenumber + "'" + "," + "'" + obj.Paymethod + "'" + "," + "'" + obj.Workername +
                                           "'" + "," + "'" + obj.Jobnumber + "')");

            try
            {
                if (term == true)
                {
                    return(term);
                }
            }
            catch (MySqlException e)
            {
                MessageBox.Show(e.Message, "提示", MessageBoxButtons.OK);
            }
            finally
            {
                con.Close();
            }

            return(term);
        }
Esempio n. 10
0
 public void AddSaleTest()
 {
     try
     {
         var listDetalle = new List <SaleDetailEntity>();
         listDetalle.Add(new SaleDetailEntity()
         {
             Amount         = 10,
             ProductBrandId = 4,
             Price          = 3,
         });
         listDetalle.Add(new SaleDetailEntity()
         {
             Amount         = 5,
             ProductBrandId = 5,
             Price          = 3,
         });
         var model = new SaleEntity()
         {
             LocalId       = 1,
             UserId        = 12,
             CodeVoucher   = "CODPRUEBA1",
             CustomerId    = 3,
             LstSaleDetail = listDetalle,
         };
         var postResult = ConstantHelpers.PostUrlAsync(Baseurl, "SAV/sales", model).Result;
         AreEqual("Success", postResult.Message);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Esempio n. 11
0
        private void AddSaleEntityRec(int GoodID, List <List <Option> > optionList, int level, List <Option> currentList, decimal Price)
        {
            if (level == optionList.Count)
            {
                var goodEntity = db.GoodEntities.Find(GoodID);

                var newEntity = new SaleEntity()
                {
                    Price        = Price,
                    GoodEntityID = GoodID,
                    GoodEntity   = goodEntity
                };
                newEntity.AttributeOptions = new HashSet <Option>();
                foreach (var option in currentList)
                {
                    newEntity.AttributeOptions.Add(option);
                }

                db.SaleEntities.Add(newEntity);
            }
            else
            {
                foreach (Option opt in optionList[level])
                {
                    currentList.Add(opt);
                    AddSaleEntityRec(GoodID, optionList, level + 1, currentList, Price);
                    currentList.Remove(opt);
                }
            }
        }
Esempio n. 12
0
        public async Task <ActionResult> Post([FromBody] ICollection <SaleCreationDTO> saleCreationDTO)
        {
            if (saleCreationDTO.Count > 0)
            {
                using (var transaction = dbContext.Database.BeginTransaction())
                {
                    try
                    {
                        // Add sale
                        var sale = new SaleEntity
                        {
                            SaleDate = DateTime.UtcNow,
                            Status   = 1
                        };
                        await dbContext.Sales.AddAsync(sale);

                        await dbContext.SaveChangesAsync();

                        int saleId = sale.SaleId;

                        //Add Sale products
                        foreach (var product in saleCreationDTO)
                        {
                            var saleProduct = mapper.Map <SaleProductCreationDTO>(product);
                            saleProduct.SaleId      = saleId;
                            saleProduct.ProductId   = product.Product.ProductId;
                            saleProduct.WarehouseId = product.Warehouse.WarehouseId;
                            saleProduct.SalePrice   = product.Product.SalePrice;
                            saleProduct.Quantity    = product.SaleQuantity;

                            var newSaleProduct = mapper.Map <SaleProductEntity>(saleProduct);
                            await dbContext.SaleProduct.AddAsync(newSaleProduct);

                            // Update Inventory quantities
                            var inventory = await dbContext.Inventories.FirstAsync(a => a.InventoryId == product.InventoryId);

                            inventory.Quantity = inventory.Quantity - product.SaleQuantity;
                        }

                        await dbContext.SaveChangesAsync();

                        // Commit transaction
                        transaction.Commit();

                        var saleDTO = mapper.Map <SaleDTO>(sale);

                        return(new CreatedAtRouteResult("getSale", new { id = sale.SaleId }, saleDTO));
                    }
                    catch (Exception ex)
                    {
                        return(StatusCode(500));
                    }
                }
            }
            else
            {
                return(BadRequest(new { message = "Sale info is empty" }));
            }
        }
Esempio n. 13
0
 public static void CreateSale(SaleEntity oSale)
 {
     using (var db = new SalesContext())
     {
         db.Sales.Add(oSale);
         db.SaveChanges();
     }
 }
 public SaleEntity FindSale(string query)
 {
     using (IGridReader reader = QueryMultiple("dbo.SPFindSale", new { query = ToSqlSafe(query) }))
     {
         SaleEntity sale = reader.Read <SaleEntity>().First();
         sale.Items = reader.Read <SaleItemEntity>();
         return(sale);
     }
 }
Esempio n. 15
0
 public static GrpcSale Present(Sale sale)
 {
     return(new GrpcSale()
     {
         CreatedAt = sale.CreatedAt.ToString(),
         Id = sale.Id.ToString(),
         PlatformId = sale.PlatformSaleId,
         Status = SaleEntity.StatusToString(sale.Status)
     });
 }
Esempio n. 16
0
        public async Task <IHttpActionResult> GetSaleEntityByID(int SaleID)
        {
            SaleEntity saleEntity = await db.SaleEntities.FindAsync(SaleID);

            if (saleEntity == null)
            {
                return(NotFound());
            }
            return(Ok(saleEntity));
        }
        public async Task <IHttpActionResult> PostSaleEntity(SaleEntity saleEntity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.SaleEntities.Add(saleEntity);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = saleEntity.SaleEntityID }, saleEntity));
        }
        public async Task <IHttpActionResult> DeleteSaleEntity(int id)
        {
            SaleEntity saleEntity = await db.SaleEntities.FindAsync(id);

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

            db.SaleEntities.Remove(saleEntity);
            await db.SaveChangesAsync();

            return(Ok(saleEntity));
        }
        /// <summary>
        /// Convert database model to business model.
        /// </summary>
        /// <param name="db">The database model.</param>
        /// <returns>The business model.</returns>
        public static SaleDetails ToBusinessModel(this SaleEntity db)
        {
            if (db == null)
            {
                return(null);
            }

            return(new SaleDetails()
            {
                TransactionId = db.TransactionId,
                Date = db.Date,
                Amount = db.Amount,
                Notes = db.Notes,
            });
        }
Esempio n. 20
0
        public SaleEntity Convert(Sale source, string shop)
        {
            if (source == null)
            {
                return(null);
            }

            var result = new SaleEntity
            {
                PartitionKey = $"{shop}_{source.ISBN}",
                RowKey       = source.Date.ToString("s"),
                Seller       = source.Seller
            };

            return(result);
        }
Esempio n. 21
0
        public void SalvarVenda()
        {
            ProductEntity product = new ProductEntity()
            {
                Id = 1, Name = "Arroz", Price = 10, Discount = 5, Stock = 200
            };
            SaleEntity sale = new SaleEntity();

            //sale.Product.Add(product);


            Moq.Mock <IRepositorySale> mock = new Moq.Mock <IRepositorySale>();


            IRepositorySale repository = mock.Object;
        }
        public static async Task <string> RegisterNewSaleAsync(RegisterSaleRequest request)
        {
            try
            {
                var sale = SaleUseCases.CreateNewSale.Execute(request);
                await SaleEntity.ValidateNewSale(sale);

                await SaleUseCases.RegisterSale.Execute(sale);

                return(sale.Id.ToString());
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <inheritdoc />
        public async Task <SaleDetails> GetSaleAsync(string transactionId)
        {
            // Validate
            Ensure.String.IsNotNullOrWhiteSpace(transactionId, optsFn: o => o.WithException(new SaleExceptions.TransactionIdRequired()));
            Ensure.String.HasLengthBetween(transactionId, 1, 32, optsFn: o => o.WithException(new SaleExceptions.TransactionIdInvalid()));
            Ensure.String.IsAllLettersOrDigits(transactionId, optsFn: o => o.WithException(new SaleExceptions.TransactionIdInvalid()));

            // Lookup sale
            SaleEntity sale = await this.Repository.FindAsync(transactionId).ConfigureAwait(false);

            if (sale == null)
            {
                throw new SaleExceptions.NotFound();
            }

            // Convert to business model
            return(sale.ToBusinessModel());
        }
Esempio n. 24
0
        public static void InsertNewSale(Guid usuarioId, Guid clienteId, string userName, string clientName, DateTime saleDate, float saleValue, float salePaidValue, int numberSoldPieces, string description)
        {
            var newSale = new SaleEntity()
            {
                ClienteId        = clienteId,
                ClientName       = clientName,
                NumberSoldPieces = numberSoldPieces,
                SaleDate         = saleDate,
                VendaId          = Guid.NewGuid(),
                SalePaidValue    = salePaidValue,
                SaleValue        = saleValue,
                UsuarioId        = usuarioId,
                UserName         = userName,
                Description      = description
            };

            SalesRepository.Get().InsertNewSale(newSale);
        }
        public async Task <String> Sale(SaleModel sale)
        {
            try{
                var                      identity         = HttpContext.User.Identity as ClaimsIdentity;
                api_docsClient           clienteAPI       = new api_docsClient(_clientFactory.CreateClient("FermeBackendClient"));
                List <ProductSaleEntity> productsSalesApi = new List <ProductSaleEntity>();
                foreach (var product in sale.Cart)
                {
                    ProductSaleEntity productSaleAPI = new ProductSaleEntity();
                    productSaleAPI.Product = new ProductEntity {
                        Id = product.Id
                    };
                    productSaleAPI.Quantity = 1;
                    productsSalesApi.Add(productSaleAPI);
                }
                SaleEntity saleApi = new SaleEntity
                {
                    Products_sale = productsSalesApi,
                    User          = new UserEntity
                    {
                        Id = long.Parse(identity.FindFirst("Id").Value)
                    },
                    Document = new DocumentEntity
                    {
                        Document_type = new DocumentTypeEntity
                        {
                            Id = int.Parse(sale.DocumentType)
                        }
                    },
                    Payment_method = new PaymentMethodEntity
                    {
                        Id = 1
                    }
                };
                Console.Out.WriteLine(JsonConvert.SerializeObject(saleApi));
                await clienteAPI.RecordedSaleUsingPOSTAsync(saleApi);
            }
            catch (Exception ex) {
                Console.Out.WriteLine(ex.Message);
                throw (ex);
            }

            return(JsonConvert.SerializeObject("OK"));
        }
Esempio n. 26
0
        public async Task <IHttpActionResult> DeleteSaleEntity(int GoodID, [FromBody] CartRequest cartRequest)
        {
            var usr = (User)HttpContext.Current.User;

            int deleteNum = -1;

            if (cartRequest != null && cartRequest.Number != null)
            {
                deleteNum = cartRequest.Number ?? -1;
            }
            SaleEntity saleEntity = await db.SaleEntities.FindAsync(GoodID);

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

            CartRecord record;

            try
            {
                record = await db.CartRecords.FirstAsync(u => u.SaleEntityID == saleEntity.SaleEntityID);
            }
            catch (InvalidOperationException _)
            {
                return(NotFound());
            }
            if (deleteNum == -1)
            {
                db.CartRecords.Remove(record);
            }
            else
            {
                record.RecordNum -= deleteNum;
                if (record.RecordNum <= 0)
                {
                    db.CartRecords.Remove(record);
                }
            }

            await db.SaveChangesAsync();

            return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NoContent)));
        }
Esempio n. 27
0
        public async Task <IHttpActionResult> AddToCart(int GoodID, [FromBody] CartRequest cartRequest)
        {
            var usr = (User)HttpContext.Current.User;

            System.Diagnostics.Debug.WriteLine("Enter the function");
            int addNumber = 1;

            if (cartRequest != null && cartRequest.Number != null)
            {
                addNumber = cartRequest.Number ?? 1;
            }
            SaleEntity saleEntity = await db.SaleEntities.FindAsync(GoodID);

            if (saleEntity == null)
            {
                System.Diagnostics.Debug.WriteLine("Not found saleEntity");
                return(NotFound());
            }
            System.Diagnostics.Debug.WriteLine("GetCarts has:" + usr.NickName);
            CartRecord record;

            try
            {
                record = await db.CartRecords.FirstAsync(u => u.SaleEntityID == saleEntity.SaleEntityID);

                System.Diagnostics.Debug.WriteLine("Found Record.");
            } catch (InvalidOperationException _)
            {
                System.Diagnostics.Debug.WriteLine("Record not found, so create it");
                record = new CartRecord()
                {
                    RecordNum    = 0,
                    UserID       = usr.UserID,
                    SaleEntityID = GoodID
                };
                db.CartRecords.Add(record);
            }

            record.RecordNum += addNumber;
            await db.SaveChangesAsync();

            return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NoContent)));
        }
Esempio n. 28
0
    public async Task <ApiError> UpdateAsync(SaleModel model)
    {
        var checkresult = await ValidateModelAsync(model, true);

        if (!checkresult.Successful)
        {
            return(checkresult);
        }
        SaleEntity entity = model !;

        try
        {
            return(ApiError.FromDalResult(await _saleRepository.UpdateAsync(entity)));
        }
        catch (Exception ex)
        {
            return(ApiError.FromException(ex));
        }
    }
Esempio n. 29
0
        public String NumberVoucher(List <SaleEntity> listSale)
        {
            String     code     = "N°";
            SaleEntity lastSale = listSale.OrderByDescending(x => x.SaleId).FirstOrDefault();

            if (listSale.Count() > 0)
            {
                Int32 numberVoucher = listSale.Count() + 1;
                for (int i = numberVoucher.ToString().Length; i < 8; i++)
                {
                    code = code + "0";
                }
                code = code + numberVoucher.ToString();
            }
            else
            {
                code = code + "00000001";
            }
            return(code);
        }
Esempio n. 30
0
    public string CreateFollowUp()
    {
        SaleEntity sale = AgentFactory.GetSaleAgent().GetSaleEntity(SuperStateManager.GetCurrentId("sale"));

        if (sale != null)
        {
            AppointmentAgent  agent = new AppointmentAgent();
            AppointmentEntity app   = agent.CreateDefaultAppointmentEntityByType(SuperOffice.Data.TaskType.Appointment);
            app.Contact     = sale.Contact;
            app.Person      = sale.Person;
            app.Associate   = sale.Associate;
            app.Description = "Sample Follow-up from Sale " + sale.SaleId;
            app.StartDate   = DateTime.Today.AddDays(7);
            app.EndDate     = app.StartDate;
            app             = agent.SaveAppointmentEntity(app);
            return(app.AppointmentId.ToString());
        }
        else
        {
            return(String.Empty);
        }
    }