Пример #1
0
        public IHttpActionResult PostSupplier(SupplierDetail supplierReceived)
        {
            var context = new ClipperDBEntities();

            context.SupplierDetails.Add(supplierReceived);
            try
            {
                context.SaveChanges();
                return(Ok());
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                Exception raise = dbEx;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",
                                                       validationErrors.Entry.Entity.ToString(),
                                                       validationError.ErrorMessage);
                        raise = new InvalidOperationException(message, raise);
                    }
                }
                throw raise;
            }
            catch (Exception ex)
            {
                // Exception raise = new Exception(HandleException(ex));
                Exception raise = ex.InnerException;
                throw raise;
            }
        }
Пример #2
0
        // Author: KyawThiha, Yeo Jia Hui
        //Create New Supplier
        public IActionResult CreateNewSupplier()
        {
            if (getUserRole().Equals(""))
            {
                return(RedirectToAction("Login", "Login"));
            }
            //Security
            if (!(getUserRole() == DeptRole.StoreClerk.ToString() ||
                  getUserRole() == DeptRole.StoreSupervisor.ToString() ||
                  getUserRole() == DeptRole.StoreManager.ToString()))
            {
                return(RedirectToAction(_filterService.Filter(getUserRole()), "Dept"));
            }
            var newSupplier = new Supplier();

            newSupplier.SupplierDetails = new List <SupplierDetail>();

            var stationeries = _dbContext.Stationeries.ToList();

            foreach (var stationary in stationeries)
            {
                var sDetail = new SupplierDetail();
                sDetail.Stationery = stationary;
                newSupplier.SupplierDetails.Add(sDetail);
            }

            Console.WriteLine(newSupplier);
            ViewData["username"] = HttpContext.Session.GetString("username");
            return(View(newSupplier));
        }
Пример #3
0
        public IHttpActionResult Put(int id, SupplierDetail supplier)
        {
            var            context        = new ClipperDBEntities();
            SupplierDetail SupplierStatus = context.SupplierDetails.Find(id);

            if (supplier == null)
            {
                return(NotFound());
            }
            else if (supplier == null)
            {
                ArgumentNullException argumentNullException = new ArgumentNullException();
                return(InternalServerError(argumentNullException));
            }
            else
            {
                SupplierDetail SupplierUpdate = context.SupplierDetails
                                                .Where(e => e.SupplierDetailsID == supplier.SupplierDetailsID).FirstOrDefault();

                if (SupplierUpdate != null)
                {
                    context.Entry(SupplierUpdate).CurrentValues.SetValues(supplier);
                }
            }
            context.SaveChanges();
            return(Ok(supplier));
        }
Пример #4
0
        public IHttpActionResult Post(List <SupplierDetail> supplierDataReceived)
        {
            SupplierDetail supplier = new SupplierDetail();
            var            context  = new ClipperDBEntities();

            foreach (SupplierDetail supplierData in supplierDataReceived)
            {
                context.SupplierDetails.Add(supplierData);
            }
            try
            {
                context.SaveChanges();
                return(Ok());
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                Exception raise = dbEx;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",
                                                       validationErrors.Entry.Entity.ToString(),
                                                       validationError.ErrorMessage);
                        raise = new InvalidOperationException(message, raise);
                    }
                }
                return(InternalServerError(dbEx));
            }
        }
Пример #5
0
        public ActionResult AddSupplier(SupplierTypeModel supplier)
        {
            var            supplierServiceClient = new ServiceReference1.SupplierServiceClient();
            SupplierDetail newSupplier           = new SupplierDetail
            {
                CompanyName  = supplier.CompanyName,
                ContactName  = supplier.ContactName,
                ContactTitle = supplier.ContactTitle,
                Country      = supplier.Country,
                Address      = supplier.Address,
                City         = supplier.City,
                Fax          = supplier.Fax,
                Region       = supplier.Region,
                Tel          = supplier.Tel,
                Website      = supplier.Website,
            };

            if (supplierServiceClient.AddSupplier(newSupplier))
            {
                Console.WriteLine("supplier a été ajouté");
                return(View());
            }
            else
            {
                return(View());
            }
        }
Пример #6
0
        //HOW DO WE ADD THE SUPPLIER
        public async Task <IActionResult> Create(int [] SelectedSuppliers, [Bind("ProductID,SKU,Name,Price,Description")] Product product)
        {
            //finds next SKU
            product.SKU = GenerateNextSKU.GetNextSKU(_context);
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                //add connections to suppliers
                //first, find the PRODUCT you just added
                Product dbProduct = _context.Products.FirstOrDefault(c => c.SKU == product.SKU);

                //loop through selected departments and add them
                foreach (int i in SelectedSuppliers)
                {
                    Supplier       dbSupplier = _context.Suppliers.Find(i);
                    SupplierDetail cd         = new SupplierDetail();
                    cd.Product  = dbProduct;
                    cd.Supplier = dbSupplier;
                    _context.SupplierDetails.Add(cd);
                    _context.SaveChanges();
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
 public int AddSupplierDetail(SupplierDetail sd)
 {
     using (EntityModel em = new EntityModel())
     {
         em.SupplierDetails.Add(sd);
         return(em.SaveChanges());
     }
 }
        public ActionResult DeleteConfirmed(int id)
        {
            SupplierDetail supplierDetail = db.SupplierDetail.Find(id);

            db.SupplierDetail.Remove(supplierDetail);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #9
0
 public ActionResult Edit([Bind(Include = "SupplierId,SupplierName,SupplierEmail,SupplierPhone")] SupplierDetail supplierDetail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(supplierDetail).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(supplierDetail));
 }
Пример #10
0
        public ActionResult Create([Bind(Include = "SupplierId,SupplierName,SupplierEmail,SupplierPhone")] SupplierDetail supplierDetail)
        {
            if (ModelState.IsValid)
            {
                db.SupplierDetails.Add(supplierDetail);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(supplierDetail));
        }
Пример #11
0
        //取得供應商資料
        public ActionResult Create(string id)
        {
            log.Info("http get mehtod:" + id);
            SupplierManage supplierService = new SupplierManage();
            SupplierDetail singleForm      = new SupplierDetail();

            supplierService.getSupplierBySupId(id);
            singleForm.sup         = supplierService.supplier;
            singleForm.contactItem = supplierService.contactList;
            log.Debug("Supplier ID:" + singleForm.sup.SUPPLIER_ID);
            return(View(singleForm));
        }
        // GET: SupplierDetails/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SupplierDetail supplierDetail = db.SupplierDetail.Find(id);

            if (supplierDetail == null)
            {
                return(HttpNotFound());
            }
            return(View(supplierDetail));
        }
 public ActionResult Edit([Bind(Include = "SupplierDetailID,SupplierID,ContactNumber,Address,ContactPersonName,DateCreated,DateModified,ModifiedBy")] SupplierDetail supplierDetail)
 {
     if (ModelState.IsValid)
     {
         supplierDetail.DateModified    = DateTime.Now;
         supplierDetail.ModifiedBy      = Convert.ToInt32(HttpContext.Session["UserAccountID"]);
         db.Entry(supplierDetail).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ModifiedBy = new SelectList(db.UserAccounts, "UserAccountID", "Email", supplierDetail.ModifiedBy);
     ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "SupplierEmail", supplierDetail.SupplierID);
     return(View(supplierDetail));
 }
        public int UpdateSupplierDetails(SupplierDetail sp)
        {
            using (EntityModel em = new EntityModel())
            {
                SupplierDetail spDetail = this.GetSupplierDetail(sp.SupplierCode, sp.ItemCode);

                spDetail.Price           = sp.Price;
                spDetail.ItemCode        = sp.ItemCode;
                em.Entry(spDetail).State = EntityState.Modified;


                return(em.SaveChanges());
            }
        }
        // GET: SupplierDetails/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SupplierDetail supplierDetail = db.SupplierDetail.Find(id);

            if (supplierDetail == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ModifiedBy = new SelectList(db.UserAccounts, "UserAccountID", "Email", supplierDetail.ModifiedBy);
            ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "SupplierEmail", supplierDetail.SupplierID);
            return(View(supplierDetail));
        }
Пример #16
0
        public IHttpActionResult Delete(int id)
        {
            var            context  = new ClipperDBEntities();
            SupplierDetail Supplier = context.SupplierDetails.Find(id);

            if (Supplier == null)
            {
                return(NotFound());
            }
            else
            {
                context.SupplierDetails.Remove(Supplier);
                context.SaveChanges();
                return(Ok(Supplier));
            }
        }
Пример #17
0
        public IHttpActionResult Get(int id)
        {
            var            context  = new ClipperDBEntities();
            SupplierDetail supplier = context.SupplierDetails.Find(id);

            if (supplier == null)
            {
                return(NotFound());
            }
            else
            {
                context.Configuration.ProxyCreationEnabled = false;
                var supplierFound = context.SupplierDetails.First(e => e.SupplierDetailsID == id);
                return(Ok(supplierFound));
            }
        }
Пример #18
0
 public static bool ReqUpdateSupplier(SupplierDetail sd)
 {
     using (var context = new ContosoContext())
     {
         var supplier = context.Suppliers.Single(s => s.SupplierID == sd.SupplierId);
         supplier.Address      = sd.Address;
         supplier.City         = sd.City;
         supplier.Fax          = sd.Fax;
         supplier.Phone        = sd.Tel;
         supplier.Region       = sd.Region;
         supplier.CompanyName  = sd.CompanyName;
         supplier.Country      = sd.Country;
         supplier.ContactTitle = sd.ContactName;
         supplier.HomePage     = sd.Website;
         supplier.ContactName  = sd.ContactName;
         context.SaveChanges();
         return(true);
     }
 }
Пример #19
0
        private async Task SetModel()
        {
            List <Supplier> Suppliers = new List <Supplier>();
            List <Models.ExternalData.VwSrmAhmSupplier>     VwSrmAhmSuppliers      = new List <Models.ExternalData.VwSrmAhmSupplier> ();
            List <Models.ExternalData.VwSrmDeliveryPrimary> VwSrmDeliveryPrimaries = new List <Models.ExternalData.VwSrmDeliveryPrimary>();

            Suppliers = await _context.Supplier
                        .Include(s => s.Status)
                        .Include(s => s.Category)
                        .Include(s => s.Comments)
                        .Include(s => s.Calls)
                        .Include("Calls.CallResponse")
                        .Include(s => s.Escalation)
                        .OrderByDescending(c => c.CreateDate)
                        .ToListAsync();

            var supplierNos = Suppliers.Select(s => s.SupplierNo).ToList();

            VwSrmAhmSuppliers = await _externalcontext.VwSrmAhmSuppliers
                                .Where(v => supplierNos
                                       .Any(s => s == v.AhmSupplierNo)).ToListAsync();

            VwSrmDeliveryPrimaries = await _externalcontext.VwSrmDeliveryPrimaries
                                     .Where(v => supplierNos
                                            .Any(s => s == v.AhmSupplierNo)).ToListAsync();

            SupplierDetails = new List <SupplierDetail>();

            foreach (Supplier supplier in Suppliers)
            {
                SupplierDetail supplierDetail = new SupplierDetail
                {
                    Supplier             = supplier,
                    VwSrmAhmSupplier     = VwSrmAhmSuppliers.Where(s => s.AhmSupplierNo == supplier.SupplierNo).FirstOrDefault(),
                    VwSrmDeliveryPrimary = VwSrmDeliveryPrimaries.Where(s => s.AhmSupplierNo == supplier.SupplierNo).FirstOrDefault()
                };
                SupplierDetails.Add(supplierDetail);
            }
        }
Пример #20
0
 public static bool ReqAddSupplier(SupplierDetail sd)
 {
     using (var context = new ContosoContext())
     {
         var supplier = new Suppliers
         {
             SupplierID   = sd.SupplierId,
             ContactName  = sd.ContactName,
             Fax          = sd.Fax,
             City         = sd.City,
             Region       = sd.Region,
             Phone        = sd.Tel,
             Address      = sd.Address,
             ContactTitle = sd.ContactTitle,
             CompanyName  = sd.CompanyName,
             Country      = sd.Country,
             HomePage     = sd.Website
         };
         context.Suppliers.Add(supplier);
         context.SaveChanges();
         return(true);
     }
 }
Пример #21
0
        public ActionResult Edit(SupplierTypeModel supplier)
        {
            var            supplierServiceClient = new ServiceReference1.SupplierServiceClient();
            SupplierDetail newSupplier           = new SupplierDetail
            {
                CompanyName  = supplier.CompanyName,
                ContactName  = supplier.ContactName,
                ContactTitle = supplier.ContactTitle,
                Country      = supplier.Country,
                Address      = supplier.Address,
                City         = supplier.City,
                Fax          = supplier.Fax,
                Region       = supplier.Region,
                Tel          = supplier.Tel,
                Website      = supplier.Website,
            };

            newSupplier.SupplierId = (long)Session["SupplierIdModified"];

            supplierServiceClient.UpdateSupplier(newSupplier);
            Session["SupplierIdModified"] = -1;
            return(RedirectToAction("Index"));
        }
Пример #22
0
 public bool AddSupplier(SupplierDetail sd)
 {
     return(SupplierRequests.ReqAddSupplier(sd));
 }
Пример #23
0
 public bool UpdateSupplier(SupplierDetail sd)
 {
     return(SupplierRequests.ReqUpdateSupplier(sd));
 }
Пример #24
0
        public static string ExcuteData(string data)
        {
            try
            {
                SupplierDetail DataMain = JsonConvert.DeserializeObject <SupplierDetail>(data);
                if (_CurrentID == null)
                {
                    using (Models.ExecuteDataBase connFunc = new Models.ExecuteDataBase())
                    {
                        DataTable dt = connFunc.ExecuteDataTable("[YYY_sp_Product_Supplier_Insert]", CommandType.StoredProcedure,
                                                                 "@Name ", SqlDbType.Int, DataMain.Name.Replace("'", "").Trim(),
                                                                 "@Phone ", SqlDbType.NVarChar, DataMain.Phone.Replace("'", "").Trim(),
                                                                 "@Created_By", SqlDbType.Int, Comon.Global.sys_userid,
                                                                 "@Created", SqlDbType.DateTime, Comon.Comon.GetDateTimeNow(),
                                                                 "@Person ", SqlDbType.Int, DataMain.Person.Replace("'", "").Trim(),
                                                                 "@Email ", SqlDbType.Int, DataMain.Email.Replace("'", "").Trim(),
                                                                 "@Note ", SqlDbType.Int, DataMain.Note.Replace("'", "").Trim()
                                                                 );
                        if (dt.Rows.Count > 0)
                        {
                            if (dt.Rows[0][0].ToString() != "0")
                            {
                                return("Tên Hoặc Mã Đã Tồn Tại Vui Lòng Kiểm Tra Lại");
                            }
                            else
                            {
                                return("1");
                            }
                        }
                        else
                        {
                            return("1");
                        }
                    }
                }
                else
                {
                    using (Models.ExecuteDataBase connFunc = new Models.ExecuteDataBase())
                    {
                        DataTable dt = connFunc.ExecuteDataTable("YYY_sp_Product_Supplier_Update", CommandType.StoredProcedure,
                                                                 "@Name", SqlDbType.NVarChar, DataMain.Name.Replace("'", "").Trim(),
                                                                 "@Modified_By", SqlDbType.Int, Comon.Global.sys_userid,
                                                                 "@Modified", SqlDbType.DateTime, Comon.Comon.GetDateTimeNow(),
                                                                 "@currentID ", SqlDbType.Int, _CurrentID,
                                                                 "@Phone", SqlDbType.NVarChar, DataMain.Phone.Replace("'", "").Trim(),
                                                                 "@Person", SqlDbType.NVarChar, DataMain.Person.Replace("'", "").Trim(),
                                                                 "@Email ", SqlDbType.NVarChar, DataMain.Email.Replace("'", "").Trim(),
                                                                 "@Note ", SqlDbType.NVarChar, DataMain.Note.Replace("'", "").Trim()

                                                                 );
                        if (dt.Rows.Count > 0)
                        {
                            if (dt.Rows[0][0].ToString() != "0")
                            {
                                return("Tên Hoặc Mã Đã Tồn Tại Vui Lòng Kiểm Tra Lại");
                            }
                            else
                            {
                                return("1");
                            }
                        }
                        else
                        {
                            return("1");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return("0");
            }
        }
        public IActionResult Edit(Product product, int[] SelectedSuppliers)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    Product dbProduct = _context.Products
                                        .Include(s => s.SupplierDetails)
                                        .ThenInclude(s => s.Supplier)
                                        .FirstOrDefault(s => s.ProductID == product.ProductID);

                    dbProduct.ProductPrice = product.ProductPrice;
                    dbProduct.ProductName  = product.ProductName;
                    dbProduct.Description  = product.Description;

                    _context.Update(dbProduct);
                    _context.SaveChanges();

                    //edit department/course relationships

                    //loop through selected departments and find ones that need to be removed
                    List <SupplierDetail> SuppliersToRemove = new List <SupplierDetail>();
                    foreach (SupplierDetail sd in dbProduct.SupplierDetails)
                    {
                        if (SelectedSuppliers.Contains(sd.Supplier.SupplierID) == false)
                        //list of selected depts does not include this departments id
                        {
                            SuppliersToRemove.Add(sd);
                        }
                    }
                    //remove departments you found in list above - this has to be 2 separate steps because you can't
                    //iterate over a list that you are removing items from
                    foreach (SupplierDetail sd in SuppliersToRemove)
                    {
                        _context.SupplierDetails.Remove(sd);
                        _context.SaveChanges();
                    }

                    //now add the departments that are new
                    foreach (int i in SelectedSuppliers)
                    {
                        if (dbProduct.SupplierDetails.Any(s => s.Supplier.SupplierID == i) == false)
                        //this supplier has not yet been added
                        {
                            //create a new course department
                            SupplierDetail sd = new SupplierDetail();

                            //connect the new course department to the department and course
                            sd.Supplier = _context.Suppliers.Find(i);
                            sd.Product  = dbProduct;

                            //update the database
                            _context.SupplierDetails.Add(sd);
                            _context.SaveChanges();
                        }
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.ProductID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.AllSuppliers = GetAllSuppliers(product);
            return(View(product));
        }