예제 #1
0
        public async Task <IActionResult> PutSuppliers(string id, [FromForm] Suppliers suppliers)
        {
            ActionResponses actionResponses;

            if (id != suppliers.fSupplierCode)
            {
                return(BadRequest());
            }

            using (_context)
            {
                var entity = _context.tSupplier.FirstOrDefault(i => i.fSupplierCode == id);
                if (entity != null)
                {
                    entity.fSupplierCode  = suppliers.fSupplierCode;
                    entity.fSupplierName  = suppliers.fSupplierName;
                    entity.fSupplierEmail = suppliers.fSupplierEmail;
                    entity.fSupplierPhone = suppliers.fSupplierPhone;
                    entity.fRemark        = suppliers.fRemark;
                    entity.fModifiedAt    = Utilities.GetIp();
                    entity.fModifiedBy    = "Admin";
                    entity.fModifiedDate  = DateTime.Now;
                    _context.SaveChanges();
                    InsertLog("Modify Supplier Information", "Execution Success", "0");
                    actionResponses = _actionContext.tActionResponses.FirstOrDefault(x => x.fErrorCode == "0");
                    return(CreatedAtAction("GetSupplier", actionResponses));
                }
            }

            return(NoContent());
        }
        private void SetupDatabase()
        {
            using (var context = new SupplierContext(options))
            {
                var suppliers = DataHelper.GetDummySuppliers(3);
                context.AddRange(suppliers);

                context.SaveChanges();
            }
        }
예제 #3
0
        /// <summary>
        /// implementiert die Anforderung void setPreferredSupplierForProduct(Supplier s, Product c)
        /// aus technischen Gründen wurde ein weitere Parameter hinzugefügt (für sinnvolles Routing)
        /// </summary>
        /// <param name="s"> Der Supplier, dessen ID in preferredSupplier eingetragen werden soll </param>
        /// <param name="c"> Das Produkt, das aktualisert werden soll </param>
        /// <param name="productId"> Die ID des zu aktualisierenden Produkts </param>
        public void setPreferredSupplierForProduct(Supplier s, Product c, string productId)
        {
            var isSupplierThere = _supplierContext.Find <Supplier>(s.id);

            if (isSupplierThere == null)
            {
                throw new UnknownSupplierException(Constants.UnknownSupplierMessage);
            }
            var isProductThere = _supplierContext.Find <Product>(productId);

            if (isProductThere == null)
            {
                throw new UnknownProductException(Constants.UnknownProductMessage);
            }

            // TODO: update benutzen
            // Work-around
            // Update wirft Exception...
            _supplierContext.Remove <Product>(isProductThere);
            isProductThere = isProductThere.Clone(isSupplierThere.id);
            // _supplierContext.Update<Product>(isProductThere);
            _supplierContext.Add <Product>(isProductThere);
            _supplierContext.SaveChanges();
        }
예제 #4
0
        public ActionResult CreateSupplier([FromBody] Supplier supplier)
        {
            try
            {
                if (supplier == null)
                {
                    return(BadRequest("Supplier object is null"));
                }

                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid model object"));
                }

                _context.Add(supplier);
                _context.SaveChanges();

                return(StatusCode(201));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, $"Internal server error: {ex}"));
            }
        }
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new SupplierContext(
                       serviceProvider.GetRequiredService <DbContextOptions <SupplierContext> >()))
            {
                if (context.Suppliers.Any())
                {
                    return;   // Data was already seeded
                }

                var emails = new List <Email>
                {
                    new Email
                    {
                        Id           = Guid.NewGuid(),
                        EmailAddress = "*****@*****.**",
                        IsPreferred  = true
                    },
                    new Email
                    {
                        Id           = Guid.NewGuid(),
                        EmailAddress = "*****@*****.**",
                        IsPreferred  = false
                    }
                };

                var phones = new List <Phone>
                {
                    new Phone
                    {
                        Id          = Guid.NewGuid(),
                        PhoneNumber = "12341234",
                        IsPreferred = true
                    },
                    new Phone
                    {
                        Id          = Guid.NewGuid(),
                        PhoneNumber = "09870987",
                        IsPreferred = false
                    }
                };

                var suppliers = new List <Supplier>
                {
                    new Supplier
                    {
                        Id        = Guid.NewGuid(),
                        FirstName = "Spongebob",
                        LastName  = "Squarepants",
                        Emails    = new List <Email> {
                            emails.First()
                        },
                        Phones = new List <Phone> {
                            phones.First()
                        }
                    },
                    new Supplier
                    {
                        Id        = Guid.NewGuid(),
                        FirstName = "Patrick",
                        LastName  = "Star",
                        Emails    = new List <Email> {
                            emails.Skip(1).First()
                        },
                        Phones = new List <Phone> {
                            phones.Skip(1).First()
                        }
                    }
                };

                context.Emails.AddRange(emails);
                context.Phones.AddRange(phones);
                context.Suppliers.AddRange(suppliers);

                context.SaveChanges();
            }
        }
예제 #6
0
 public void Save()
 {
     _dbContext.SaveChanges();
 }