public async Task <IActionResult> Edit(long id, [Bind("ID,CompanyName,ContactName,ContactTitle,CityId,Phone,Fax")] Models.Supplier supplier)
        {
            if (id != supplier.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(supplier);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SupplierExists(supplier.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Country"] = new SelectList(_context.countries, "ID", "Name");
            ViewData["CityId"]  = new SelectList(_context.Cities.Include(e => e.Country).ToList(), "ID", "Name", supplier.CityId, "Country.Name");
            return(View(supplier));
        }
Ejemplo n.º 2
0
        // GET: AddSupplier
        public ActionResult Index()
        {
            var db       = new CodeFirst.CodeFirst();
            var supplier = new Models.Supplier();

            return(View(supplier));
        }
        private void SaveSupplierDetails(DbRepository dbRepository)
        {
            if (!ValidateRequiredFields())
            {
                return;
            }
            if (!ValidateDuplicateRecord())
            {
                return;
            }

            var repository = dbRepository;
            var supplier   = new Models.Supplier()
            {
                SupplierName    = txtSupplierName.Text,
                ContactNo       = txtContactNo.Text,
                Email           = txtEmail.Text,
                Address         = txtAddress.Text.Trim(),
                IsActive        = true,
                DateTimeCreated = DateTime.Now


                                  //CreatedBy = AccountSession.GetAccount.Id
            };

            repository.Suppliers.Add(supplier);
            repository.Commit();

            ResetToDefault();
            MessageAlert.Show("New supplier has successfully added.", "Supplier", AlertType.Info);
        }
Ejemplo n.º 4
0
        // GET: ModifySupplier
        public ActionResult Index(string SupplierID)
        {
            CodeFirst.CodeFirst db      = new CodeFirst.CodeFirst();
            Models.Supplier     myModel = new Models.Supplier();
            if (SupplierID != null)
            {
                var intSupplierID = Int32.Parse(SupplierID);
                var mySupplier    = db.Suppliers.Where(i => i.SupplierID == intSupplierID).FirstOrDefault();

                myModel.SupplierID    = mySupplier.SupplierID;
                myModel.Name          = mySupplier.Name;
                myModel.VATNumber     = mySupplier.VATNumber;
                myModel.EmailAddress  = mySupplier.EmailAddress;
                myModel.ContactNumber = mySupplier.ContactNumber;
                myModel.Bank          = mySupplier.Bank;
                myModel.AccountNumber = mySupplier.AccountNumber;
                myModel.BranchCode    = mySupplier.BranchCode;
                myModel.POAddress     = mySupplier.POAddress;
                myModel.POCity        = mySupplier.POCity;
                myModel.POAreaCode    = mySupplier.POAreaCode;

                return(View(myModel));
            }

            return(View(myModel));
        }
Ejemplo n.º 5
0
        public ActionResult Modify([Bind(Prefix = "")] Models.Supplier model)
        {
            var db = new CodeFirst.CodeFirst();

            if (ModelState.IsValid)
            {
                var Supplier = db.Suppliers.Where(v => v.SupplierID == model.SupplierID).SingleOrDefault();

                if (Supplier != null)
                {
                    Supplier.SupplierID    = model.SupplierID;
                    Supplier.Name          = model.Name;
                    Supplier.VATNumber     = model.VATNumber;
                    Supplier.EmailAddress  = model.EmailAddress;
                    Supplier.ContactNumber = model.ContactNumber;
                    Supplier.Bank          = model.Bank;
                    Supplier.AccountNumber = model.AccountNumber;
                    Supplier.BranchCode    = model.BranchCode;
                    Supplier.POAddress     = model.POAddress;
                    Supplier.POCity        = model.POCity;
                    Supplier.POAreaCode    = model.POAreaCode;
                    db.SaveChanges();
                }

                TempData["js"] = "myUpdateSuccess()";
                return(RedirectToAction("Index", "Supplier"));
            }

            return(View("Index", model));
        }
Ejemplo n.º 6
0
        public ActionResult Create(SupplierViewModels model)
        {
            var data = new ResponseModels();

            try
            {
                // TODO: Add insert logic here
                EasyBuyEntities db            = new EasyBuyEntities();
                var             checkSupplier = db.Suppliers.Where(p => p.Name == model.Name).FirstOrDefault();
                if (checkSupplier == null)
                {
                    Models.Supplier supplier = new Models.Supplier
                    {
                        Name    = model.Name,
                        Phone   = model.Phone,
                        City    = model.City,
                        Area    = model.Area,
                        Address = model.Address
                    };
                    db.Suppliers.Add(supplier);
                    db.SaveChanges();
                    data.result = 1;
                }
                else
                {
                    data.msg = "該廠商已存在,請重新建立。";
                }
            }
            catch (Exception e)
            {
                data.msg = e.Message;
            }
            return(Json(data, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Create(Models.Supplier Supplier)
        {
            ServiceRepository   serviceObj = new ServiceRepository();
            HttpResponseMessage response   = serviceObj.PostResponse("api/supplier/InsertSupplier", Supplier);

            response.EnsureSuccessStatusCode();
            return(RedirectToAction("GetAllSuppliers"));
        }
        private void ShowSupplierDetails(Models.Supplier selectedSupplier)
        {
            txtSupplierName.Text = selectedSupplier.SupplierName;
            txtAddress.Text      = selectedSupplier.Address;
            txtEmail.Text        = selectedSupplier.Email;

            txtContactNo.Text = selectedSupplier.ContactNo;
            GoToSupplierDetails();
        }
Ejemplo n.º 9
0
 public async Task CreateSupplier(Models.Supplier supplier)
 {
     using (ApplicationDbContext context = new ApplicationDbContext())
     {
         supplier.Id = Guid.NewGuid();
         context.Supplier.Add(supplier);
         await context.SaveChangesAsync();
     }
 }
Ejemplo n.º 10
0
 // GET: Supplier
 public ActionResult Index()
 {
     Models.Supplier myModel = new Models.Supplier();
     if (TempData["model"] != null)
     {
         myModel = (Models.Supplier)TempData["model"];
         TempData.Remove("model");
     }
     return(View(myModel));
 }
        public ActionResult Details(string id)
        {
            ServiceRepository   serviceObj = new ServiceRepository();
            HttpResponseMessage response   = serviceObj.GetResponse("api/supplier/GetSupplier?id=" + id);

            response.EnsureSuccessStatusCode();
            Models.Supplier Suppliers = response.Content.ReadAsAsync <Models.Supplier>().Result;
            ViewBag.Title = "All Suppliers";
            return(View(Suppliers));
        }
        private void DataGrid_Loaded(object sender, RoutedEventArgs e)
        {
            Models.Supplier supplier = new Models.Supplier();
            MyContext       _context = new MyContext();
            var             get      = _context.Suppliers.Where(u => u.isDeleted != true).ToList();

            // ... Assign ItemsSource of DataGrid.
            var grid = sender as DataGrid;

            grid.ItemsSource = get;
        }
        public async Task <IActionResult> Create([Bind("ID,CompanyName,ContactName,ContactTitle,CityId,Phone,Fax")] Models.Supplier supplier)
        {
            if (ModelState.IsValid)
            {
                _context.Add(supplier);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Country"] = new SelectList(_context.countries, "ID", "Name");
            ViewData["CityId"]  = new SelectList(_context.Cities.Include(e => e.Country).ToList(), "ID", "Name", supplier.CityId, "Country.Name");
            return(View(supplier));
        }
Ejemplo n.º 14
0
        public ActionResult Create([Bind(Prefix = "")] Models.Supplier model)
        {
            var db = new CodeFirst.CodeFirst();

            if (ModelState.IsValid)
            {
                if (db.Suppliers.Count() > 0)
                {
                    var item = db.Suppliers.OrderByDescending(a => a.SupplierID).FirstOrDefault();

                    db.Suppliers.Add(new CodeFirst.Supplier
                    {
                        SupplierID    = item.SupplierID + 1,
                        Name          = model.Name,
                        VATNumber     = model.VATNumber,
                        EmailAddress  = model.EmailAddress,
                        ContactNumber = model.ContactNumber,
                        Bank          = model.Bank,
                        AccountNumber = model.AccountNumber,
                        BranchCode    = model.BranchCode,
                        POAddress     = model.POAddress,
                        POCity        = model.POCity,
                        POAreaCode    = model.POAreaCode
                    });
                }
                else
                {
                    db.Suppliers.Add(new CodeFirst.Supplier
                    {
                        SupplierID    = 1,
                        Name          = model.Name,
                        VATNumber     = model.VATNumber,
                        EmailAddress  = model.EmailAddress,
                        ContactNumber = model.ContactNumber,
                        Bank          = model.Bank,
                        AccountNumber = model.AccountNumber,
                        BranchCode    = model.BranchCode,
                        POAddress     = model.POAddress,
                        POCity        = model.POCity,
                        POAreaCode    = model.POAreaCode
                    });
                }

                db.SaveChanges();
                model.JavaScriptToRun = "mySuccess()";
                TempData["model"]     = model;
                return(RedirectToAction("Index", "Supplier"));
            }

            return(View("Index", model));
        }
Ejemplo n.º 15
0
 public async Task EditSupplier(Models.Supplier supplier)
 {
     using (ApplicationDbContext context = new ApplicationDbContext())
     {
         var update = context.Supplier.Find(supplier.Id);
         if (update != null)
         {
             update.SupplierName    = supplier.SupplierName;
             update.SupplierContact = supplier.SupplierContact;
             update.SupplierEmail   = supplier.SupplierEmail;
             await context.SaveChangesAsync();
         }
     }
 }
Ejemplo n.º 16
0
 public Models.Supplier Get(string id)
 {
     try
     {
         Models.Supplier supplier = (from p in db.Supplier
                                     where p.CodFornecedor == id
                                     select p).AsQueryable().First();
         return(supplier);
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e);
         return(null);
     }
 }
Ejemplo n.º 17
0
        //[HttpGet]
        public ActionResult EditSupplier(string id)
        {
            Models.Supplier Suppliers = null;
            //ServiceRepository serviceObj = new ServiceRepository();
            HttpResponseMessage response = serviceObj.GetResponse("api/Supplier/GetSupplier?id=" + id.ToString());

            response.EnsureSuccessStatusCode();
            if (type != "test")
            {
                Suppliers = response.Content.ReadAsAsync <Models.Supplier>().Result;
            }

            ViewBag.Title = "All Suppliers";
            return(View("EditSupplier", Suppliers));
        }
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            string email = (value as string).Trim();

            ISupplierRepository _context = (ISupplierRepository)validationContext.GetService(typeof(ISupplierRepository));
            EmployeeLogin       login    = (EmployeeLogin)validationContext.GetService(typeof(EmployeeLogin));

            Models.Supplier        obj  = (Models.Supplier)validationContext.ObjectInstance;
            List <Models.Supplier> list = (List <Models.Supplier>)_context.FindByEmail(email, login.GetEmployee().BusinessId);

            if (list.Count > 1)
            {
                return(new ValidationResult("E-mail já cadastrado"));
            }
            if (list.Count == 1 && obj.Id != list[0].Id)
            {
                return(new ValidationResult("E-mail já cadastrado"));
            }

            return(ValidationResult.Success);
        }
        private async static Task Main()
        {
            // First Approach - Typical GoF Builder Pattern (Director <- Builder)
            var logger   = new ConsoleLogger();
            var database = new Database(Configuration.ConnectionString, logger);

            // Concrete Builders
            var bakeryPoBuilder = new BakeryPurchaseOrderBuilder();
            var coffeePoBuilder = new CoffeePurchaseOrderBuilder();

            // Director
            var poProcessor = new PurchaseOrderProcessor(logger, database);

            await poProcessor.GenerateWeeklyPurchaseOrder(bakeryPoBuilder);

            await poProcessor.GenerateWeeklyPurchaseOrder(coffeePoBuilder);


            // Second Approach - "Custom" builder using a fluent syntax
            var customOrder = new FluentPurchaseOrderBuilder();

            var items = new List <Models.LineItem> {
                new("cups", 100, 1.0m),
                new("napkins", 250, 0.3m),
            };

            var supplier = new Models.Supplier("Jenkins", "*****@*****.**", "C.I. Jenkins");

            customOrder
            .WithId("Custom_Order")
            .AtAddress("123 Riverrun Lane")
            .ForCompany("Productive Dev")
            .FromSupplier(supplier)
            .RequestDate(DateTime.UtcNow.AddDays(2))
            .ForItems(items);

            await poProcessor.SavePurchaseOrderToDatabase(customOrder);

            poProcessor.PrintPurchaseOrder(customOrder);
        }
Ejemplo n.º 20
0
 public IActionResult Update([FromBody] Models.Supplier supplier)
 {
     _unitOfWork.SupplierRepository.Update(supplier);
     _unitOfWork.Complete();
     return(new JsonResult(supplier));
 }
Ejemplo n.º 21
0
 public int Add(Models.Supplier supplier)
 {
     return(supplierRepository.Add(supplier));
 }
Ejemplo n.º 22
0
 public bool Update(Models.Supplier supplier)
 {
     return(supplierRepository.Update(supplier));
 }
Ejemplo n.º 23
0
        public async void Crud(string option)
        {
            var ID    = SupplierDgv.SelectedIndex;
            var query = await new ParseQuery <Models.Supplier>().FindAsync();
            var list  = query.Select(p => new
            {
                Id             = p.ObjectId,
                Nombre         = p.Name,
                Identificacion = p.Identification,
                p.Balance,
                Creado = p.CreatedAt
            });

            switch (option.ToLower())
            {
            //TODO: Identification validation. Returns false
            case "save":
                if (Utilities.ValidateRnc(IdentificationTxt.Text))
                {
                    if (string.IsNullOrEmpty(NameTxt.Text).Equals(false) && string.IsNullOrEmpty(IdentificationTxt.Text).Equals(false))
                    {
                        try
                        {
                            //Cuando se crea un suplidor, este debe de tener un balance de RD$0. La razón es que existe una relación balance-documentos
                            //donde el balance es la suma de todos sus documentos pendientes. Por ende, tampoco se podrá editar el balance de un suplidor directamente.
                            //De igual forma, el estado al crearlo será inactivo por default, porque el estado de un suplidor se maneja por medio del balance.
                            //Dejaré que se permita modificar el estado de un suplidor ya existente, debido a que puede que pase un tiempo y este, si se desea,
                            //pase a inactivo y tenga documentos pendientes.

                            Models.Supplier supplier;
                            if (!(IdTxt.Text.Length > 2))
                            {
                                supplier = new Models.Supplier
                                {
                                    Name           = NameTxt.Text,
                                    Balance        = 0,
                                    Identification = IdentificationTxt.Text,
                                    State          = "Inactivo",
                                    Type           = ((ComboBoxItem)TypeCbx.SelectedItem).Content.ToString()
                                };
                                await supplier.SaveAsync();

                                MessageBox.Show("Suplidor creado");
                            }
                            else
                            {
                                supplier = new Models.Supplier
                                {
                                    ObjectId       = IdTxt.Text,
                                    Name           = NameTxt.Text,
                                    Identification = IdentificationTxt.Text,
                                    State          = ((ComboBoxItem)StateCbx.SelectedItem).Content.ToString(),
                                    Type           = ((ComboBoxItem)StateCbx.SelectedItem).Content.ToString()
                                };
                                await supplier.SaveAsync();

                                MessageBox.Show("Suplidor actualizado");
                            }
                            PopulateGrid();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Cedula/RNC invalida");
                    break;
                }
                break;

            case "delete":
                try
                {
                    var element        = list.ElementAt(ID);
                    var deleteSupplier = from a in new ParseQuery <Models.Supplier>()
                                         where a.Id.Equals(element.Id)
                                         select a;

                    await deleteSupplier.FirstAsync().Result.DeleteAsync();

                    MessageBox.Show("Eliminado satisfactoriamente");
                    PopulateGrid();
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Error eliminando usuario\n{ex}");
                }

                break;
            }
        }
Ejemplo n.º 24
0
        public async Task<ActionResult> Create(SupplierViewModel model, FormCollection collect)
        {

            #region Cathing model errors
            var error = ModelState.Values.SelectMany(e => e.Errors);
            var errors = ModelState
    .Where(x => x.Value.Errors.Count > 0)
    .Select(x => new { x.Key, x.Value.Errors })
    .ToArray();
            #endregion

            #region Prep Utilities
            SupplierContext dataSocket = new SupplierContext();
            ApplicationDbContext context = new ApplicationDbContext();
            var roleStore = new RoleStore<IdentityRole>(context);
            UserStore<ApplicationUser> myStore = new UserStore<ApplicationUser>(context);
            ApplicationUserManager userMgr = new ApplicationUserManager(myStore);
            var roleManager = new RoleManager<IdentityRole>(roleStore);
            #endregion

            #region Bend the rules
            try
            {
                if(collect.GetValue("SupplierType").AttemptedValue == "0")
                { /*Book Supplier*/ model.RegisterNewSupplier.SupplierType = true; }
                else if (collect.GetValue("SupplierType").AttemptedValue == "1")
                { /*Technology Supplier*/ model.RegisterNewSupplier.SupplierType = false; }
                if (ModelState.ContainsKey("SupplierType"))
                    ModelState["SupplierType"].Errors.Clear();
            }
            catch
            { ModelState.AddModelError("SupplierType", "Please select a valid supplier type from dropdown !"); }
            #endregion
            try
            {
                if (ModelState.IsValid)
                {
                    #region Register Supplier

                    var user = new ApplicationUser() { UserName = model.RegisterNewSupplier.Email, Email = model.RegisterNewSupplier.Email, Address = model.RegisterNewSupplier.Address, PhoneNumber = model.RegisterNewSupplier.ContactPersonNumber };
                    Models.Supplier supplier = new Models.Supplier { Name = model.RegisterNewSupplier.Name, ContactPerson = model.RegisterNewSupplier.ContactPerson, Fax = model.RegisterNewSupplier.Fax, ContactPersonNumber = model.RegisterNewSupplier.ContactPersonNumber, LastName = model.RegisterNewSupplier.LastName, User_Id = user.Id, IsBookSupplier = model.RegisterNewSupplier.SupplierType };
                    user.Carts = new Cart { DateLastModified = DateTime.Now };
                    user.Wishlists = new Wishlist { Status = false };
                    IdentityResult result = await userMgr.CreateAsync(user, model.RegisterNewSupplier.Password);
                    roleManager.Create(new IdentityRole { Name = "supplier" });
                    userMgr.AddToRole(user.Id, "supplier");
                    //dataSocket.Suppliers.Add(supplier);
                    dataSocket.Suppliers.Add(supplier);

                    dataSocket.SaveChanges();

                     #endregion

                    return RedirectToAction("Index", "Admin", null);
                }
                #region Set Up dropdown

                model.SupplierType = new List<SelectListItem>();
                model.SupplierType.Add(
                    new SelectListItem { Text = "Please Select Supplier Type", Value = "", Selected = true }
                );
                model.SupplierType.Add(
                    new SelectListItem { Text = "Book Supplier", Value = "0" }
                    );
                model.SupplierType.Add(
                    new SelectListItem { Text = "Technology Supplier", Value = "1" }
                    );
                ViewData["SupplierType"] = model.SupplierType;
                #endregion
                return View(model);

            }
            catch
            {
                #region Set Up dropdown

                model.SupplierType = new List<SelectListItem>();
                model.SupplierType.Add(
                    new SelectListItem { Text = "Please Select Supplier Type", Value = "", Selected = true }
                );
                model.SupplierType.Add(
                    new SelectListItem { Text = "Book Supplier", Value = "0" }
                    );
                model.SupplierType.Add(
                    new SelectListItem { Text = "Technology Supplier", Value = "1" }
                    );
                ViewData["SupplierType"] = model.SupplierType;
                #endregion
                return View(model);
            }
        }