public ActionResult Customers()
        {
            ICollection <Customer> custLst = new List <Customer>();

            Models.CustomerModel cm = new Models.CustomerModel();

            custLst = api.GetCustomers(cm);

            return(View(custLst));
        }
        public ActionResult CreateAccount(IFormCollection collection, Models.CustomerModel cust)
        {
            Customer c             = new Customer();
            bool     usernametaken = false;

            var customers = db.GetCustomers();

            foreach (var i in customers)
            {
                if (i.Username == cust.Username)
                {
                    usernametaken = true;
                }
            }
            if (usernametaken == true)
            {
                ViewData["Text"] = "Username is taken.";
                return(View()); //include error catcher
            }
            else
            {
                c.Username = cust.Username;
            }
            if (c.MatchPassword(cust.Password, cust.ReEnterPassword) == true)
            {
                c.Password = cust.Password;
            }
            else
            {
                ViewData["Text"] = "Passwords do not match.";
                return(View()); //include error catcher
            }

            c.FirstName = cust.FirstName;
            c.LastName  = cust.LastName;
            c.Add1      = cust.Add1;
            c.Add2      = cust.Add2;
            c.City      = cust.City;
            c.State     = cust.State;
            c.Country   = cust.Country;
            c.ZipCode   = cust.ZipCode;

            try
            {
                db.AddCustomer(c);
                db.Save();
                c.CustID           = db.GetCustomerByUser(cust.Username).CustID;
                TempData["custid"] = c.CustID;
                return(RedirectToAction("Locations", "Home"));
            }
            catch
            {
                return(RedirectToAction("LogIn"));
            }
        }
 public ActionResult Edit(Guid id, FormCollection collection)
 {
     try
     {
         // TODO: Add update logic here
         Models.CustomerModel customerModel = new Models.CustomerModel();
         UpdateModel(customerModel);
         customerRepository.UpdateCustomer(customerModel);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View("EditCustomer"));
     }
 }
 public ActionResult Create(FormCollection collection)
 {
     try
     {
         // TODO: Add insert logic here
         Models.CustomerModel customerModel = new Models.CustomerModel();
         UpdateModel(customerModel);
         customerRepository.InsertCustomer(customerModel);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View("CreateCustomer"));
     }
 }
        public ActionResult ViewRestaurantData_Customers()
        {
            var o = db.GetOrders();
            var c = db.GetCustomers();

            bool isincluded = false;
            int  location   = (int)TempData["location"];

            TempData.Keep();

            custlist = new List <CustomerModel>();

            foreach (var i in c)
            {
                isincluded = false;
                foreach (var j in o)
                {
                    if (i.CustID == j.CustID && location == j.Location)
                    {
                        isincluded = true;
                    }
                }

                if (isincluded == true)
                {
                    cust           = new Models.CustomerModel();
                    cust.CustID    = i.CustID;
                    cust.FirstName = i.FirstName;
                    cust.LastName  = i.LastName;
                    cust.Add1      = i.Add1;
                    cust.Add2      = i.Add2;
                    cust.City      = i.City;
                    cust.State     = i.State;
                    cust.Country   = i.Country;
                    cust.ZipCode   = i.ZipCode;
                    cust.Username  = i.Username;
                    custlist.Add(cust);
                }
            }
            return(View(custlist));
        }
        public List <DataAccessPoint.Customer> GetCustomers(Models.CustomerModel customer)
        {
            //System.Drawing.Rectangle rec = new System.Drawing.Rectangle();

            NorthwindEntities entities = new NorthwindEntities();

            entities.Configuration.ProxyCreationEnabled = false;
            try
            {
                List <Customer> lst = new List <Customer>();
                lst = (from c in entities.Customers.Take(10)
                       //where c.ContactName.StartsWith(customer.fullName) || string.IsNullOrEmpty(customer.fullName)
                       select c).ToList();

                return(lst);
            }
            catch (Exception e)
            {
                string errMsg = e.Message;
                return(null);
            }
        }
        public ActionResult LogIn(IFormCollection collection, Models.CustomerModel cust)
        {
            var customer = db.GetCustomers();

            foreach (var i in customer)
            {
                if (i.Username == cust.Username)
                {
                    if (i.Password == cust.Password)
                    {
                        var user = db.GetCustomerByUser(i.Username);
                        c.Username = i.Username;
                        c.Password = i.Password;

                        c.FirstName = i.FirstName;
                        c.LastName  = i.LastName;
                        c.Add1      = i.Add1;
                        c.Add2      = i.Add2;
                        c.City      = i.City;
                        c.State     = i.State;
                        c.Country   = i.Country;
                        c.ZipCode   = i.ZipCode;

                        c.CustID = i.CustID;

                        TempData["custid"] = c.CustID;

                        return(RedirectToAction("Locations", "Home"));
                    }
                    ViewData["Text"] = "Incorrect Password.";
                    return(View());
                }
            }

            ViewData["Text"] = "Username does not exist.";
            return(View());
        }
 // GET: Customer/Delete/5
 public ActionResult Delete(Guid id)
 {
     Models.CustomerModel customerModel = customerRepository.GetCustomerByID(id);
     return(View("DeleteCustomer", customerModel));
 }
 // GET: Customer/Details/5
 public ActionResult Details(Guid id)
 {
     Models.CustomerModel customerModel = customerRepository.GetCustomerByID(id);
     return(View("CustomerDetails", customerModel));
 }
 // GET: Customer/Edit/5
 public ActionResult Edit(int id)
 {
     Models.CustomerModel customerModel = customerRepository.GetCustomerById(id);
     return(View("EditCustomer", customerModel));
 }
Example #11
0
        public ActionResult SaveCustomer(Models.CustomerModel data)
        {
            if (!ModelState.IsValid)
            {
                if (data.cust_id == 0)
                {
                    _db = new QSoft_WUEntities();
                    DAL.Customer code = _db.Customer.Where(p => p.cuscode == data.cuscode).FirstOrDefault();
                    if (code != null)
                    {
                        return(Json(false, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        System.Web.HttpContext.Current.Application.Lock();
                        _db = new QSoft_WUEntities();
                        _db.Customer.Add(new DAL.Customer
                        {
                            cust_id        = data.cust_id,
                            cuscode        = data.cuscode,
                            cusname1       = data.cusname1,
                            cusname11      = data.cusname11,
                            cusname2       = data.cusname2,
                            cusname21      = data.cusname21,
                            cusaddress1    = data.cusaddress1,
                            cusaddress2    = data.cusaddress2,
                            cuszip         = data.cuszip,
                            custel         = data.custel,
                            cusfax         = data.cusfax,
                            cusmobile      = data.cusmobile,
                            datecontact    = data.datecontact,
                            dateinact      = data.dateinact,
                            status         = data.status,
                            p_id           = data.p_id,
                            t_id           = data.t_id,
                            niti           = data.niti,
                            acc_code       = data.acc_code,
                            gcusid         = data.gcusid,
                            contaddress1   = data.contaddress1,
                            contaddress2   = data.contaddress2,
                            contzip        = data.contzip,
                            notebill       = data.notebill,
                            noteth         = data.noteth,
                            noteen         = data.noteen,
                            cuszid         = data.cuszid,
                            credittermtype = data.credittermtype,
                            credittermday  = data.credittermday,
                            creditmoney    = data.creditmoney,
                            saleid         = data.saleid,
                            contname       = data.contname,
                            blacklist      = data.blacklist,
                            reason         = data.reason,
                            grade          = data.grade,
                            conname        = data.conname,
                            cusidinvoice   = data.cusidinvoice,
                            cusidbill      = data.cusidbill,
                            cusidsend      = data.cusidsend,
                            sendid         = data.sendid,
                            ncostcode      = data.ncostcode,
                            ndiscountcode  = data.ndiscountcode,
                            discountlist   = data.discountlist,
                            discountbill   = data.discountbill,
                            note1          = data.note1,
                            note2          = data.note2,
                            note3          = data.note3,
                            note4          = data.note4,
                            note5          = data.note5,
                            note6          = data.note6,
                            note7          = data.note7,
                            note8          = data.note8,
                            note9          = data.note9,
                            note10         = data.note10,
                            ccode          = data.ccode,
                            ShippingDate   = data.ShippingDate
                        });
                        _db.SaveChanges();
                        System.Web.HttpContext.Current.Application.UnLock();
                        return(Json(true, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            if (ModelState.IsValid)
            {
                if (data.cust_id != 0)
                {
                    _db = new QSoft_WUEntities();
                    DAL.Customer code = _db.Customer.Where(p => p.cuscode == data.cuscode && p.cust_id != data.cust_id).FirstOrDefault();
                    if (code != null)
                    {
                        return(Json(false, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        DAL.Customer edit = _db.Customer.Where(p => p.cust_id == data.cust_id).FirstOrDefault();

                        edit.cuscode        = data.cuscode;
                        edit.cusname1       = data.cusname1;
                        edit.cusname11      = data.cusname11;
                        edit.cusname2       = data.cusname2;
                        edit.cusname21      = data.cusname21;
                        edit.cusaddress1    = data.cusaddress1;
                        edit.cusaddress2    = data.cusaddress2;
                        edit.cuszip         = data.cuszip;
                        edit.custel         = data.custel;
                        edit.cusfax         = data.cusfax;
                        edit.cusmobile      = data.cusmobile;
                        edit.datecontact    = data.datecontact;
                        edit.dateinact      = data.dateinact;
                        edit.status         = data.status;
                        edit.p_id           = data.p_id;
                        edit.t_id           = data.t_id;
                        edit.niti           = data.niti;
                        edit.acc_code       = data.acc_code;
                        edit.gcusid         = data.gcusid;
                        edit.contaddress1   = data.contaddress1;
                        edit.contaddress2   = data.contaddress2;
                        edit.contzip        = data.contzip;
                        edit.notebill       = data.notebill;
                        edit.noteth         = data.noteth;
                        edit.noteen         = data.noteen;
                        edit.cuszid         = data.cuszid;
                        edit.credittermtype = data.credittermtype;
                        edit.credittermday  = data.credittermday;
                        edit.creditmoney    = data.creditmoney;
                        edit.saleid         = data.saleid;
                        edit.contname       = data.contname;
                        edit.blacklist      = data.blacklist;
                        edit.reason         = data.reason;
                        edit.grade          = data.grade;
                        edit.conname        = data.conname;
                        edit.cusidinvoice   = data.cusidinvoice;
                        edit.cusidbill      = data.cusidbill;
                        edit.cusidsend      = data.cusidsend;
                        edit.sendid         = data.sendid;
                        edit.ncostcode      = data.ncostcode;
                        edit.ndiscountcode  = data.ndiscountcode;
                        edit.discountlist   = data.discountlist;
                        edit.discountbill   = data.discountbill;
                        edit.note1          = data.note1;
                        edit.note2          = data.note2;
                        edit.note3          = data.note3;
                        edit.note4          = data.note4;
                        edit.note5          = data.note5;
                        edit.note6          = data.note6;
                        edit.note7          = data.note7;
                        edit.note8          = data.note8;
                        edit.note9          = data.note9;
                        edit.note10         = data.note10;
                        edit.ccode          = data.ccode;
                        edit.ShippingDate   = data.ShippingDate;
                        _db.SaveChanges();
                        return(Json(true, JsonRequestBehavior.AllowGet));
                    }
                }
            }

            return(View(data));
        }