Ejemplo n.º 1
0
        public async Task <IActionResult> delete(discountSetupStoreList discSetupStoreList)
        {
            try
            {
                List <DiscountSetupStore> list = discSetupStoreList.discSetupStore;

                for (int i = 0; i < list.Count; i++)
                {
                    var store             = _context.Store.Where(x => x.Code == list[i].Store.Code).First();
                    var discSetupStoreObj = _context.DiscountSetupStore.Where(x => x.StoreId == store.Id).First();
                    _context.DiscountSetupStore.Remove(discSetupStoreObj);
                    _context.SaveChanges();
                }

                return(StatusCode(200, new
                {
                    status = "200",
                    delete = true,
                    message = "Deleted successfully!"
                }));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, new
                {
                    status = "500",
                    delete = false,
                    message = ex.ToString()
                }));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> create(discountSetupStoreList discSetupStoreList)
        {
            try
            {
                List <DiscountSetupStore> list = discSetupStoreList.discSetupStore;

                for (int i = 0; i < list.Count; i++)
                {
                    bool discExist  = false;
                    bool storeExist = false;
                    discExist = _context.DiscountSetup.Any(c => c.Id == list[i].DiscountId);
                    var store = _context.Store.Where(x => x.Code == list[i].Store.Code).First();
                    storeExist = _context.DiscountSetupStore.Any(c => c.StoreId == store.Id);

                    if (discExist && !storeExist)
                    {
                        DiscountSetupStore setupStore = new DiscountSetupStore();
                        setupStore.DiscountId = list[i].DiscountId;
                        setupStore.StoreId    = store.Id;
                        _context.Add(setupStore);
                        _context.SaveChanges();
                    }
                    else
                    {
                        return(StatusCode(404, new
                        {
                            status = "404",
                            create = false,
                            message = "Cannot create a record, store id already exist or discount id not exist."
                        }));
                    }
                }

                return(StatusCode(200, new
                {
                    status = "200",
                    create = true,
                    message = "Created successfully!"
                }));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, new
                {
                    status = "500",
                    create = false,
                    message = ex.ToString()
                }));
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> update(discountSetupStoreList discSetupStoreList)
        {
            try
            {
                List <DiscountSetupStore> list = discSetupStoreList.discSetupStore;

                for (int i = 0; i < list.Count; i++)
                {
                    bool discExist = false;
                    var  store     = _context.Store.Where(x => x.Code == list[i].Store.Code).First();
                    discExist = _context.DiscountSetupStore.Any(c => c.StoreId == store.Id);
                    if (discExist == true)
                    {
                        var discSetupStoreObj = _context.DiscountSetupStore.Where(x => x.StoreId == store.Id).First();
                        discSetupStoreObj.DiscountId = list[i].DiscountId;

                        _context.DiscountSetupStore.Update(discSetupStoreObj);
                        _context.SaveChanges();
                    }
                    else
                    {
                        return(StatusCode(404, new
                        {
                            status = "404",
                            update = false,
                            message = "Discount code not found."
                        }));
                    }
                }

                return(StatusCode(200, new
                {
                    status = "200",
                    update = true,
                    message = "updated successfully!"
                }));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, new
                {
                    status = "500",
                    create = false,
                    message = ex.ToString()
                }));
            }
        }