Ejemplo n.º 1
0
        string IWereMobileRest.AddSetting(string name, string value, string description, string id)
        {
            using (var db = new WereMobileEntities())
            {
                Setting setting;

                setting = db.Setting.FirstOrDefault(s => s.ID.Equals(id));

                if (setting == null)
                {
                    setting = new Setting();
                }

                setting.ID          = id;
                setting.Name        = name;
                setting.Value       = value;
                setting.Description = description;


                db.Setting.AddOrUpdate(setting);

                db.SaveChanges();

                return(setting.ID);
            }
        }
Ejemplo n.º 2
0
        string IWereMobileRest.AddProduct(string name, decimal price, double quantity, string number, string id)
        {
            using (var db = new WereMobileEntities())
            {
                Product prod;
                prod = db.Product.FirstOrDefault(p => p.ID.Equals(id));

                if (prod == null)
                {
                    prod = new Product();
                }

                prod.ID            = id;
                prod.Name          = name;
                prod.ProductNumber = number;
                prod.Price         = price;
                prod.Quantity      = quantity;


                db.Product.AddOrUpdate(prod);


                db.SaveChanges();

                return(prod.ID);
            }
        }
Ejemplo n.º 3
0
        bool IWereMobileRest.DeleteSetting(string id)
        {
            using (var db = new WereMobileEntities())
            {
                var setting = db.Setting.FirstOrDefault(s => s.ID.Equals(id));

                if (setting != null)
                {
                    db.Setting.Remove(setting);
                    db.SaveChanges();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 4
0
        bool IWereMobileRest.DeleteProduct(string id)
        {
            using (var db = new WereMobileEntities())
            {
                var product = db.Product.FirstOrDefault(p => p.ID.Equals(id));

                if (product != null)
                {
                    db.Product.Remove(product);
                    db.SaveChanges();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 5
0
        bool IWereMobileRest.DeleteLot(string id)
        {
            using (var db = new WereMobileEntities())
            {
                var lot = db.Lot.FirstOrDefault(l => l.ID.Equals(id));

                if (lot != null)
                {
                    db.Lot.Remove(lot);
                    db.SaveChanges();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 6
0
        bool IWereMobileRest.DeleteDocumentRow(string id)
        {
            using (var db = new WereMobileEntities())
            {
                var documentRow = db.DocumentRow.FirstOrDefault(dr => dr.ID.Equals(id));

                if (documentRow != null)
                {
                    db.DocumentRow.Remove(documentRow);
                    db.SaveChanges();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 7
0
        bool IWereMobileRest.DeleteContragent(string id)
        {
            using (var db = new WereMobileEntities())
            {
                var contragent = db.Contragent.FirstOrDefault(p => p.ID.Equals(id));

                if (contragent != null)
                {
                    db.Contragent.Remove(contragent);
                    db.SaveChanges();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 8
0
        bool IWereMobileRest.DeleteBarcode(string id)
        {
            using (var db = new WereMobileEntities())
            {
                var barcode = db.Barcode.FirstOrDefault(b => b.ID.Equals(id));

                if (barcode != null)
                {
                    db.Barcode.Remove(barcode);
                    db.SaveChanges();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 9
0
        string IWereMobileRest.AddContragent(Stream data)
        {
            StreamReader reader    = new StreamReader(data);
            string       xmlString = reader.ReadToEnd();

            byte[] byteData      = Convert.FromBase64String(xmlString);
            string decodedString = Encoding.UTF8.GetString(byteData);

            var contragents = JsonConvert.DeserializeObject <List <Contragent> >(decodedString);

            foreach (Contragent contragent in contragents)
            {
                using (var db = new WereMobileEntities())
                {
                    Contragent newContragent;

                    newContragent = db.Contragent.FirstOrDefault(p => p.ID.Equals(contragent.ID));

                    if (newContragent == null)
                    {
                        newContragent = new Contragent();
                    }

                    newContragent.ID          = contragent.ID;
                    newContragent.Name        = contragent.Name;
                    newContragent.Bulstat     = contragent.Bulstat;
                    newContragent.VatNumber   = contragent.VatNumber;
                    newContragent.City        = contragent.City;
                    newContragent.Address     = contragent.Address;
                    newContragent.Mrp         = contragent.Mrp;
                    newContragent.PhoneNumber = contragent.PhoneNumber;


                    db.Contragent.AddOrUpdate(newContragent);

                    db.SaveChanges();
                }
            }

            return(xmlString);
        }
Ejemplo n.º 10
0
        string IWereMobileRest.AddLot(Stream data)
        {
            StreamReader reader    = new StreamReader(data);
            string       xmlString = reader.ReadToEnd();

            byte[] byteData      = Convert.FromBase64String(xmlString);
            string decodedString = Encoding.UTF8.GetString(byteData);
            //byte[] base64Decoded = DatatypeConverter.parseBase64Binary(contragentsBase64String);
            var fakelots = JsonConvert.DeserializeObject <List <FakeLot> >(decodedString);

            foreach (var FakeLot in fakelots)
            {
                using (var db = new WereMobileEntities())
                {
                    var newLot = db.Lot.FirstOrDefault(p => p.ID.Equals(FakeLot.ID));

                    if (newLot == null)
                    {
                        newLot = new Lot();
                    }

                    newLot.ID        = FakeLot.ID;
                    newLot.ProductID = FakeLot.ProductID;
                    newLot.Quantity  = FakeLot.Quantity;
                    var dateFormated = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(FakeLot.ExpirationDate)).ToLocalTime();
                    var time         = dateFormated.DateTime;
                    newLot.ExpirationDate = time;
                    newLot.LotNumber      = FakeLot.LotNumber;


                    db.Lot.AddOrUpdate(newLot);

                    db.SaveChanges();
                }
            }

            return(xmlString);
        }
Ejemplo n.º 11
0
        string IWereMobileRest.AddDocument(Stream data)
        {
            StreamReader reader      = new StreamReader(data);
            string       codedString = reader.ReadToEnd();

            byte[] byteData      = Convert.FromBase64String(codedString);
            string decodedString = Encoding.UTF8.GetString(byteData);

            var fakedocuments = JsonConvert.DeserializeObject <List <FakeDocument> >(decodedString);

            foreach (var FakeDocument in fakedocuments)
            {
                using (var db = new WereMobileEntities())
                {
                    var newDocument = db.Document.FirstOrDefault(p => p.ID.Equals(FakeDocument.ID));
                    if (newDocument == null)
                    {
                        newDocument = new Document();
                    }
                    newDocument.ID             = FakeDocument.ID;
                    newDocument.SourceID       = FakeDocument.SourceID;
                    newDocument.DestinationID  = FakeDocument.DestinationID;
                    newDocument.DocumentNumber = FakeDocument.DocumentNumber;

                    var dateFormated = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(FakeDocument.Date)).ToLocalTime();
                    var time         = dateFormated.DateTime;

                    newDocument.Date = time;


                    db.Document.AddOrUpdate(newDocument);

                    db.SaveChanges();
                }
            }
            return(codedString);
        }
Ejemplo n.º 12
0
        string IWereMobileRest.AddDocumentRow(Stream data)
        {
            StreamReader reader    = new StreamReader(data);
            string       xmlString = reader.ReadToEnd();

            byte[] byteData      = Convert.FromBase64String(xmlString);
            string decodedString = Encoding.UTF8.GetString(byteData);

            var documentRows = JsonConvert.DeserializeObject <List <DocumentRow> >(decodedString);

            foreach (DocumentRow documentRow in documentRows)
            {
                using (var db = new WereMobileEntities())
                {
                    DocumentRow newDocumentRow;

                    newDocumentRow = db.DocumentRow.FirstOrDefault(dr => dr.ID.Equals(documentRow.ID));

                    if (newDocumentRow == null)
                    {
                        newDocumentRow = new DocumentRow();
                    }

                    newDocumentRow.ID         = documentRow.ID;
                    newDocumentRow.ProductID  = documentRow.ProductID;
                    newDocumentRow.LotID      = documentRow.LotID;
                    newDocumentRow.Quantity   = documentRow.Quantity;
                    newDocumentRow.Sum        = documentRow.Sum;
                    newDocumentRow.DocumentID = documentRow.DocumentID;

                    db.DocumentRow.AddOrUpdate(newDocumentRow);

                    db.SaveChanges();
                }
            }
            return(xmlString);
        }
Ejemplo n.º 13
0
        string IWereMobileRest.AddBarcode(string barcodenumber, string productid, string id)
        {
            using (var db = new WereMobileEntities())
            {
                Barcode barcode;

                barcode = db.Barcode.FirstOrDefault(b => b.ID.Equals(id));
                if (barcode == null)
                {
                    barcode = new Barcode();
                }

                barcode.ID            = id;
                barcode.BarcodeNumber = barcodenumber;
                barcode.ProductID     = productid;


                db.Barcode.AddOrUpdate(barcode);

                db.SaveChanges();

                return(barcode.ID);
            }
        }