Ejemplo n.º 1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         entities = new CustomerEntities();
     }
 }
        public JsonResult SaveCustomer(CustomerViewModel customer)
        {
            using (var db = new CustomerEntities())
            {
                var cus = db.Customers.Find(customer.ID);
                if (cus != null)
                {
                    cus.Name    = customer.Name;
                    cus.Address = customer.Address;
                    cus.Phone   = customer.Phone;

                    if (db.SaveChanges() > 0)
                    {
                        return(Json(new { status = "success", response = cus }));
                    }
                    else
                    {
                        return(Json(new { status = "failed", reason = "could not save" }));
                    }
                }
                else
                {
                    return(Json(new { status = "failed", reason = "not found" }));
                }
            }
        }
Ejemplo n.º 3
0
 public IEnumerable <Customer> Get()
 {
     using (CustomerEntities entities = new CustomerEntities())
     {
         return(entities.Customer.ToList());
     }
 }
Ejemplo n.º 4
0
        public void Validate(CustomerEntities cust)
        {
            if (Regex.IsMatch(cust.CustomerName, "^[a-zA-Z]$") == false)
            {
                throw new InvalidStringException("not a valid name");
            }

            if (Regex.IsMatch(cust.CustomerAddress, @"^[0-9]+\s+([a-zA-Z]+|[a-zA-Z]+\s[a-zA-Z]+)$") == false)
            {
                throw new InvalidStringException("not a valid address");
            }

            if (Regex.IsMatch(cust.CustomerMobile, @"\+?[0-9]{10}") == false)
            {
                throw new InvalidStringException("not a valid mobile");
            }

            if (Regex.IsMatch(cust.CustomerEmail, @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$") == false)
            {
                throw new InvalidStringException("not a valid email");
            }

            if (Regex.IsMatch(cust.CustomerPan, @"^([A - Z]{ 5}\d{ 4}[A-Z]{1})$") == false)
            {
                throw new InvalidStringException("not a valid pan ");
            }
        }
Ejemplo n.º 5
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                var Cus = new CustomerEntities();
                Cus.Name         = txtName.Text;
                Cus.IDCardNumber = int.Parse(txtIDCardNumber.Text);
                Cus.Phone        = txtPhone.Text;
                Cus.Address      = txtAddress.Text;
                if (rbNam.Checked)
                {
                    Cus.Sex = true;
                }
                else
                {
                    Cus.Sex = false;
                }

                CusPro.Create(Cus);
                this.Close();
                new ManageBill();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Ejemplo n.º 6
0
 public Customer Get(int id)
 {
     using (CustomerEntities entities = new CustomerEntities())
     {
         return(entities.Customer.FirstOrDefault(e => e.Id == id));
     }
 }
Ejemplo n.º 7
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,IdCode,FullName,PhoneNumber,Address,Gender,Status")] CustomerEntities customerEntities)
        {
            if (id != customerEntities.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(customerEntities);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CustomerEntitiesExists(customerEntities.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(customerEntities));
        }
 public ActionResult Search(CustomerVM customerVmValue)
 {
     using (var db = new CustomerEntities())
     {
         var customerSearchResults = from customerRec in db.Customers
                                     where ((customerVmValue.Name == null) || (customerRec.Name == customerVmValue.Name.Trim())) &&
                                     ((customerVmValue.City == null) || (customerRec.City == customerVmValue.City.Trim())) &&
                                     ((customerVmValue.State == null) || (customerRec.State == customerVmValue.State.Trim()))
                                     select new
         {
             Name = customerRec.Name
             ,
             City = customerRec.City
             ,
             State = customerRec.State
         };
         List <Customer> lstCustomer = new  List <Customer>();
         foreach (var record in customerSearchResults)
         {
             Customer customerValue = new Customer();
             customerValue.Name  = record.Name;
             customerValue.City  = record.City;
             customerValue.State = record.State;
             lstCustomer.Add(customerValue);
         }
         customerVmValue.Customers = lstCustomer;
         return(View(customerVmValue));
     }
 }
Ejemplo n.º 9
0
 public CustomerEntities GetCustomerByCustomerID_DAL(string CustomerID)
 {
     try
     {
         foreach (CustomerEntities cust in Customers)
         {
             if (cust.CustomerID.Equals(CustomerID) == true)
             {
                 Console.WriteLine("Customer Name :-" + cust.CustomerName);
                 Console.WriteLine("Customer Address :-" + cust.CustomerAddress);
                 Console.WriteLine("Customer Mobile no :-" + cust.CustomerMobile);
                 Console.WriteLine("Customer Email :-" + cust.CustomerEmail);
                 Console.WriteLine("Customer Pan :-" + cust.CustomerPan);
                 return(cust);
             }
         }
         //if customerID not found
         CustomerEntities c = new CustomerEntities();
         return(c);
     }
     catch (Exception e)
     {
         CustomerEntities c = new CustomerEntities();
         return(c);
     }
 }
Ejemplo n.º 10
0
        public CustomerEntities GetCustomerByCustomerID_DAL(string CustomerID)
        {
            bool validate = false;

            try
            {
                CustomerEntities customerEntitiesTemporary = new CustomerEntities();

                List <CustomerEntities> custlist = DeserializeFromJSON("Customerdata.txt"); //we have to search customer through CustomerID

                foreach (CustomerEntities cust in custlist)                                 //foreach will search the list
                {
                    if (cust.CustomerID.Equals(CustomerID) == true)
                    {
                        validate = true;
                        customerEntitiesTemporary = cust;
                        break;
                    }
                }
                if (validate != true)
                {
                    throw new CustomerDoesNotExistException("Customer Not available based on given CustomerID");
                }
                //if customerID not found
                return(customerEntitiesTemporary);
            }
            catch (Exception e)
            {
                CustomerEntities c = new CustomerEntities();
                return(c);
            }
        }
Ejemplo n.º 11
0
        public PartialViewResult UserList()
        {
            CustomerEntities           db   = new CustomerEntities();
            List <CustomerInformation> user = db.CustomerInformations.ToList();

            return(PartialView(user));
        }
        public ActionResult Index(int?page)
        {
            var pageNumber = page ?? 1;
            var pageSize   = 2;

            using (var db = new CustomerEntities())
            {
                //var cust = db.Database.SqlQuery<Customer>("Select * from customer").ToList();
                //var customersList = db.Customers.OrderBy(x => x.Id).Select(x => new CustomerViewModel
                //{
                //    ID = x.Id,
                //    Name = x.Name,
                //    Address = x.Address,
                //    Phone = x.Phone
                //}).ToPagedList(pageNumber, pageSize);

                var customersList = db.Customers.OrderBy(x => x.Id).ToPagedList(pageNumber, pageSize);

                var model = new GridViewModel
                {
                    Customers = customersList
                };

                return(View(model));
            }
        }
        public async Task <Customer> CreateOrUpdateAsync(Customer customer)
        {
            Customer record = null;

            using (var db = new CustomerEntities())
            {
                if (customer.Id != 0)
                {
                    record = db.Customers.SingleOrDefault(c => c.Id == customer.Id);

                    if (record != null)
                    {
                        record.FirstName   = customer.FirstName;
                        record.LastName    = customer.LastName;
                        record.PhoneNumber = customer.PhoneNumber;
                        record.Email       = customer.Email;
                        await db.SaveChangesAsync();
                    }
                }
                else
                {
                    record             = db.Customers.Create();
                    record.FirstName   = customer.FirstName;
                    record.LastName    = customer.LastName;
                    record.Email       = customer.Email;
                    record.PhoneNumber = customer.PhoneNumber;

                    db.Customers.Add(record);
                    await db.SaveChangesAsync();
                }


                return(record);
            }
        }
Ejemplo n.º 14
0
        public ActionResult Create(CustomerEntities xct)
        {
            CustomerServices cs = new CustomerServices();

            cs.Create(xct);

            return(View());
        }
Ejemplo n.º 15
0
        public async Task <ActionResult> ViewCustomer(int Id)
        {
            CustomerEntities customers = (await new nuDirectApiController().GetAllCustomers()).FirstOrDefault(x => x.CustomerId == Id);

            ViewBag.Endpoints = (await new nuDirectApiController().GetAllEndpoints()).Where(x => x.CustomerId == customers.CustomerId);

            return(View(customers));
        }
Ejemplo n.º 16
0
        public int AddCustomer(CustomerEntities ce)
        {
            var res = (from c in dbEntites.Employees
                       where c.Pan == ce.Pan
                       select c).Count();
            var res2 = (from c in dbEntites.Customers
                        where c.Pan == ce.Pan
                        select c).Count();

            if (res > 0 || res2 > 0)
            {
                return(0);
            }
            else
            {
                var cd = dbEntites.Customers.OrderByDescending(t => t.CustId).FirstOrDefault();
                if (cd == null)
                {
                    ce.CustId = "MLA10001";
                }
                else
                {
                    ce.CustId = "MLA" + (Convert.ToInt32(cd.CustId.Substring(3, 5)) + 1).ToString();
                }
                Customer c = new Customer()
                {
                    CustId   = ce.CustId,
                    CustName = ce.CustName,
                    Pan      = ce.Pan,
                    Dob      = ce.Dob,
                    Password = ce.Password,
                    Status   = true,
                    Email    = ce.Email
                };
                dbEntites.Customers.Add(c);

                var ac = dbEntites.SavingsAccounts.OrderByDescending(t => t.Accountid).FirstOrDefault();
                if (ac == null)
                {
                    ce.Accountid = "SB10001";
                }
                else
                {
                    ce.Accountid = "SB" + (Convert.ToInt32(ac.Accountid.Substring(2, 5)) + 1).ToString();
                }
                SavingsAccount sac = new SavingsAccount()
                {
                    Accountid = ce.Accountid,
                    CustId    = ce.CustId,
                    Balance   = ce.balance
                };
                dbEntites.SavingsAccounts.Add(sac);
                dbEntites.SaveChanges();

                return(1);
            }
        }
Ejemplo n.º 17
0
        public IHttpActionResult RegisterCustomer(CustomerEntities model)
        {
            try
            {
                using (var ts = new TransactionScope())
                {
                    if (model == null)
                    {
                        response.Data    = null;
                        response.Error   = true;
                        response.Message = "Error, Empty model";
                        return(Content(HttpStatusCode.BadRequest, response));
                    }
                    else
                    {
                        Customer customer = new Customer();

                        if (context.Customer.FirstOrDefault(x => x.Username == model.Username) != null)
                        {
                            response.Data    = null;
                            response.Error   = true;
                            response.Message = "Error, Existing customer";
                            return(Content(HttpStatusCode.BadRequest, response));
                        }
                        else
                        {
                            context.Customer.Add(customer);

                            customer.Names            = model.Names;
                            customer.LastNames        = model.LastNames;
                            customer.DocumentIdentity = model.DocumentIdentity;
                            customer.Password         = CipherLogic.Cipher(CipherAction.Encrypt, CipherType.UserPassword, model.Password);
                            customer.BirthdayDate     = model.Birthday;
                            customer.Username         = model.Username;
                            customer.Status           = ConstantHelpers.Status.ACTIVE;
                            customer.DepartmentId     = model.DepartmentId;
                            customer.ProvinceId       = model.ProvinceId;
                            customer.DistrictId       = model.DistrictId;
                            customer.Phone            = model.Phone;

                            context.SaveChanges();

                            response.Data    = null;
                            response.Error   = false;
                            response.Message = "Success, saved customer";
                        }

                        ts.Complete();
                    }
                }
                return(Ok(response));
            }
            catch (Exception ex)
            {
                return(Unauthorized());
            }
        }
 public JsonResult CheckEmail(Customer customer)
 {
     bool answer;
     using (CustomerEntities cEntity = new CustomerEntities())
     {
         var email = cEntity.Customers.Where(x=>x.email == customer.email).FirstOrDefault();
         answer = (email != null) ? false : true;
     }
     return Json(answer, JsonRequestBehavior.AllowGet);
 }
Ejemplo n.º 19
0
        public bool AddCustomerBL(CustomerEntities cust)
        {
            CustomerBL customer = new CustomerBL();

            Validate(cust);

            CustomerDAL obj = new CustomerDAL();

            return(obj.AddCustomerDAL(cust));
        }
Ejemplo n.º 20
0
        private static void SetDbHTTPContext()
        {
            DbContext dbContext = new CustomerEntities();

            //dbContext.Database.Log = (sql) =>
            //{
            //    System.IO.File.AppendText(HostingEnvironment.MapPath(@"~\App_Data\logs.txt"));
            //};
            HttpContext.Current.Items[Repositories.FieldKey.DB_CONTEXT_KEY] = dbContext;
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Load data method.
        /// </summary>
        /// <returns>Returns - Data</returns>
        private List <SalesOrderDetail> LoadData()
        {
            // Initialization.
            List <SalesOrderDetail> lst = new List <SalesOrderDetail>();
            CustomerEntities        ctx = new CustomerEntities();

            lst = ctx.SalesOrderDetails.ToList();
            try
            {
                // Initialization.
                //string line = string.Empty;
                //string srcFilePath = "Content/files/SalesOrderDetail.txt";
                //var rootPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
                //var fullPath = Path.Combine(rootPath, srcFilePath);
                //string filePath = new Uri(fullPath).LocalPath;
                //StreamReader sr = new StreamReader(new FileStream(filePath, FileMode.Open, FileAccess.Read));

                //// Read file.
                //while ((line = sr.ReadLine()) != null)
                //{
                //    // Initialization.
                //    SalesOrderDetail infoObj = new SalesOrderDetail();
                //    string[] info = line.Split(',');

                //    // Setting.
                //    infoObj.Sr = Convert.ToInt32(info[0].ToString());
                //    infoObj.OrderTrackNumber = info[1].ToString();
                //    infoObj.Quantity = Convert.ToInt32(info[2].ToString());
                //    infoObj.ProductName = info[3].ToString();
                //    infoObj.SpecialOffer = info[4].ToString();
                //    infoObj.UnitPrice = Convert.ToDecimal(info[5].ToString());
                //    infoObj.UnitPriceDiscount = Convert.ToDecimal(info[6].ToString());

                //    // Adding.
                //    lst.Add(infoObj);
                //    ctx.SalesOrderDetails.Add(infoObj);

                //}

                //ctx.SaveChanges();

                // Closing.
                //sr.Dispose();
                //sr.Close();
            }
            catch (Exception ex)
            {
                // info.
                Console.Write(ex);
            }

            // info.
            return(lst);
        }
Ejemplo n.º 22
0
        public async Task <IActionResult> Create([Bind("Id,IdCode,FullName,PhoneNumber,Address,Gender,Status")] CustomerEntities customerEntities)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customerEntities);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customerEntities));
        }
Ejemplo n.º 23
0
        public string Add(CustomerInformation model)
        {
            CustomerEntities    db = new CustomerEntities();
            CustomerInformation cs = new CustomerInformation();

            cs.Name    = model.Name;
            cs.Surname = model.Surname;
            db.CustomerInformations.Add(cs);
            db.SaveChanges();
            return("1");
        }
        public async Task <List <Customer> > ListAllAsync()
        {
            List <Customer> customers = new List <Customer>();

            using (var db = new CustomerEntities())
            {
                customers = await db.Customers.ToListAsync();
            }

            return(customers);
        }
Ejemplo n.º 25
0
        public static void CustomerEFPageTest()
        {
            //using (var context = new CustomerEntities())
            //{
            //    // 删除之前的数据
            //    context.Database.ExecuteSqlCommand("delete from Chapter3.Customer");

            //    // 添加新的测试数据
            //    context.Customers.Add(new Customer
            //    {
            //        Name = "Roberts, Jill",
            //        Email = "*****@*****.**"
            //    });
            //    context.Customers.Add(new Customer
            //    {
            //        Name = "Robertson, Alice",
            //        Email = "*****@*****.**"
            //    });
            //    context.Customers.Add(new Customer
            //    {
            //        Name = "Rogers, Steven",
            //        Email = "*****@*****.**"
            //    });
            //    context.Customers.Add(new Customer
            //    {
            //        Name = "Roe, Allen",
            //        Email = "*****@*****.**"
            //    });
            //    context.Customers.Add(new Customer
            //    {
            //        Name = "Jones, Chris",
            //        Email = "*****@*****.**"
            //    });
            //    context.SaveChanges();
            //}

            using (var context = new CustomerEntities())
            {
                string match     = "Ro";
                int    pageIndex = 1;
                int    pageSize  = 3;

                var customers = context.Customers.Where(m => m.Name.Contains(match))
                                .OrderBy(m => m.Name)
                                .Skip(pageIndex * pageSize)
                                .Take(pageSize);
                Console.WriteLine("Customers Ro*");
                foreach (var customer in customers)
                {
                    Console.WriteLine("{0} [email: {1}]", customer.Name, customer.Email);
                }
            }
        }
 public ActionResult Search()
 {
     using (var db = new CustomerEntities())
     {
         var customer = db.Customers.ToList();
         var data     = new CustomerVM()
         {
             Customers = customer
         };
         return(View(data));
     }
 }
 public ActionResult Account()
 {
     if (ModelState.IsValid)
     {
         using (CustomerEntities cEntities = new CustomerEntities())
         {
             int customerID = Convert.ToInt32(Session["customerID"]);
             ViewBag.customerInfo = cEntities.Customers.Where(x => x.customer_ID == customerID).ToList();
         }
     }
     return View();
 }
Ejemplo n.º 28
0
 public Customer Post(Customer customer)
 {
     using (CustomerEntities entities = new CustomerEntities())
     {
         entities.Customer.Add(new Customer()
         {
             Name = "Poopoo"
         });
         entities.SaveChanges();
         return(entities.Customer.FirstOrDefault());
     }
 }
 public ActionResult Account(Customer customer)
 {
     if (ModelState.IsValid)
     {
         using (CustomerEntities cEntities = new CustomerEntities())
         {
             customer.customer_ID = Convert.ToInt32(Session["customerID"]);
             cEntities.Entry(customer).State = EntityState.Modified;
             cEntities.SaveChanges();
             return RedirectToAction("Account");
         }
     }
     return View();
 }
Ejemplo n.º 30
0
        public void UpdateCustomerByCustomerID_BL(CustomerEntities customerEntities)
        {
            Validate(customerEntities);
            ValidateCustomerID(customerEntities.CustomerID);
            CustomerDAL      obj = new CustomerDAL();
            CustomerEntities customerEntitiesTemporary = new CustomerEntities();

            customerEntitiesTemporary = obj.GetCustomerByCustomerID_DAL(customerEntities.CustomerID);
            customerEntitiesTemporary.CustomerName    = customerEntities.CustomerName;
            customerEntitiesTemporary.CustomerID      = customerEntities.CustomerID;
            customerEntitiesTemporary.CustomerMobile  = customerEntities.CustomerMobile;
            customerEntitiesTemporary.CustomerEmail   = customerEntitiesTemporary.CustomerEmail;
            customerEntitiesTemporary.CustomerAddress = customerEntitiesTemporary.CustomerAddress;
            customerEntitiesTemporary.CustomerPan     = customerEntitiesTemporary.CustomerPan;
        }
Ejemplo n.º 31
0
 public static List <CustomerEntities> CustomersList; // list of customers is created by passing CustomerEntities class as data type
 public bool AddCustomerDAL(CustomerEntities customerEntities)
 {
     try
     {
         DateTime Time       = DateTime.Now;
         string   customerID = Time.ToString("yyyyMMddhhmmss");
         customerEntities.CustomerID = customerID;
         CustomersList.Add(customerEntities);  //Customer is added in the list
         return(SerialiazeIntoJSON(CustomersList, "Customerdata.txt"));
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Ejemplo n.º 32
0
        public static List <CustomerEntities> Customers; // list of customers is created by passing CustomerEntities class as data type
        public bool AddCustomerDAL(CustomerEntities c)
        {
            try
            {
                DateTime Time       = DateTime.Now;
                string   customerID = Time.ToString("yyyyMMddhhmmss");
                c.CustomerID = customerID;
                Customers.Add(c);  //Customer is added in the list

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
        public async Task <bool> DeleteAsync(int id)
        {
            bool isDeleted = false;

            using (var db = new CustomerEntities())
            {
                var customer = db.Customers.SingleOrDefault(c => c.Id == id);

                if (customer != null)
                {
                    db.Entry(customer).State = EntityState.Deleted;
                    await db.SaveChangesAsync();

                    isDeleted = true;
                }
            }

            return(isDeleted);
        }
Ejemplo n.º 34
0
        public bool AddCustomer(string customer)
        {
            try
            {
                using (var db = new CustomerEntities())
                {
                    var newCustomer = db.Main_Dim_CustomerSet.Create();
                    newCustomer.Customer_name = customer;

                    db.Main_Dim_CustomerSet.Add(newCustomer);
                    db.SaveChanges();
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
 public ActionResult Register(Customer customer, CustomerAddress customerAddress, CustomerLogin customerLogin)
 {
     string viewChange = "";
     try
     {
         if (ModelState.IsValid)
         {
             //encrypt the password
             customerLogin.password = HashKey.GetHashKey(customerLogin.password);
             //inserting into customers table
             using (CustomerEntities cEntityy = new CustomerEntities())
             {
                 cEntityy.Customers.Add(customer);
                 cEntityy.SaveChanges();
             }
             using (CustomerAddressEntities caEntity = new CustomerAddressEntities())
             {
                 customerAddress.customer_ID = customer.customer_ID;
                 //inserting into customer address table
                 caEntity.CustomerAddresses.Add(customerAddress);
                 caEntity.SaveChanges();
             }
             using (CustomerLoginEntities clEntity = new CustomerLoginEntities())
             {
                 customerLogin.customer_ID = customer.customer_ID;
                 customerLogin.email = customer.email;
                 customerLogin.dateCreated = DateTime.Now;
                 //inserting into customer login table
                 clEntity.CustomerLogins.Add(customerLogin);
                 clEntity.SaveChanges();
                 return RedirectToAction("Index", "Customer");
             }
         }
         else
         {
             viewChange = "LoginRegister";
         }
     }
     catch(EntryPointNotFoundException ex){}
     catch (Exception ex) { viewChange = "LoginRegister"; }
     return View(viewChange);
 }
Ejemplo n.º 36
0
        public bool UserExist(string username)
        {
            try
            {
                using (var db = new CustomerEntities())
                {
                    if (db.Main_UsersSet.Any(o => o.Username.Equals(username)))
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }

            }
            catch (Exception ex)
            {
                return false;
            }
        }
Ejemplo n.º 37
0
 public bool UnitExist(string ID)
 {
     try
     {
         using (var db = new CustomerEntities())
         {
             if (db.Main_Bridge_Customer_UnitSet.Any(o => o.Main_Dim_UnitSet.UnitID.Equals(ID)))
             {
                 return true;
             }
             else
             {
                 return false;
             }
         }
     }
     catch
     {
         return false;
     }
 }
Ejemplo n.º 38
0
        public bool Adduser(string username, string password, string customer)
        {
            try
            {
                using (var db = new CustomerEntities())
                {
                    var newUser = db.Main_UsersSet.Create();
                    newUser.Username = username;
                    newUser.Password = password;
                    newUser.Customer = customer;

                    db.Main_UsersSet.Add(newUser);
                    db.SaveChanges();

                    return true;
                }
            }

            catch (Exception ex)
            {
                return false;
            }
        }
Ejemplo n.º 39
0
        public bool AddUnitToCustomerTable(string UnitID, string customer)
        {
            try
            {
                using (var dbCustomer = new CustomerEntities())
                {
                    var newBridgeUnit = dbCustomer.Main_Bridge_Customer_UnitSet.Create();
                    var newUnit = dbCustomer.Main_Dim_UnitSet.Create();
                    var cust = dbCustomer.Main_Dim_CustomerSet.Where(o => o.Customer_name.Equals(customer)).First();

                    newUnit.UnitID = UnitID;

                    newBridgeUnit.Main_Dim_UnitSet = newUnit;
                    newBridgeUnit.Main_Dim_CustomerSet = cust;

                    dbCustomer.Main_Bridge_Customer_UnitSet.Add(newBridgeUnit);
                    dbCustomer.SaveChanges();
                }

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }

            /*switch (customer)
            {
                case "RegionH":
                    try
                    {
                        using (var dbCustomer = new CustomerEntities())
                        {
                            var newBridgeUnit = dbCustomer.Main_Bridge_Customer_UnitSet.Create();
                            var newUnit = dbCustomer.Main_Dim_UnitSet.Create();
                            var cust = dbCustomer.Main_Dim_CustomerSet.Where(o => o.Customer_name.Equals(customer)).First();

                            newUnit.UnitID = UnitID;

                            newBridgeUnit.Main_Dim_UnitSet = newUnit;
                            newBridgeUnit.Main_Dim_CustomerSet = cust;

                            dbCustomer.Main_Bridge_Customer_UnitSet.Add(newBridgeUnit);
                            dbCustomer.SaveChanges();
                        }

                        return true;
                    }
                    catch (Exception ex)
                    {
                        return false;
                    }

                case "Lundbeck":
                    try
                    {
                        using (var db = new LundbeckEntities())
                        {
                            //CHANGE!!
                        }
                        return true;
                    }
                    catch (Exception ex)
                    {
                        return false;
                    }

                default:
                    return false;
            }*/
        }
Ejemplo n.º 40
0
        /*public string getCustomerForUnit(string unitID)
        {
            try
            {
                using (var db = new CustomerEntities())
                {
                    var cust = db.Main_Bridge_Customer_UnitSet.Where(o => o.Main_Dim_UnitSet.UnitID.Equals(unitID)).First();

                    return cust.Main_Dim_CustomerSet.Customer_name;
                }

            }
            catch (Exception ex)
            {
                return "Failed to retrieve Customer ID";
            }

        }*/
        public bool checkLogin(string username, string password)
        {
            try
            {
                using (var db = new CustomerEntities())
                {
                    if (db.Main_UsersSet.Any(o => o.Username.Equals(username) && o.Password.Equals(password)))
                    {
                        return true;
                    }
                    else
                    {
                        //User credentials doesn't match
                        return false;
                    }
                }

            }
            catch (Exception ex)
            {
                return false;
            }
        }
Ejemplo n.º 41
0
        public bool AddLogToMainTable(string ID, DateTime timestamp, string action)
        {
            try
            {
                using (var db = new CustomerEntities())
                {
                    var newlog = db.Main_Fact_LogsSet.Create();

                    newlog.UnitName = ID;
                    newlog.Timestamp = timestamp;
                    newlog.EventName = action;

                    db.Main_Fact_LogsSet.Add(newlog);
                    db.SaveChanges();

                    return true;
                }

            }
            catch (Exception ex)
            {
                return false;
            }
        }
 public ActionResult Index()
 {
     if (Session["customerID"] == null)
     {
         return  RedirectToAction("Index","Registration");
     }
     if (Session["customerID"] != null)
     {
         using (CustomerEntities cEntites = new CustomerEntities())
         {
             int customerID = Convert.ToInt32(Session["customerID"]);
             List<Customer> customerList = cEntites.Customers.Where(x => x.customer_ID == customerID).ToList();
             ViewBag.customerName = customerList[0].firstName + " " + customerList[0].lastName;
         }
     }
     return View();
 }
Ejemplo n.º 43
0
 public bool customerExist(string customer)
 {
     try
     {
         using (var db = new CustomerEntities())
         {
             if (db.Main_Dim_CustomerSet.Any(o => o.Customer_name.Equals(customer)))
             {
                 return true;
             }
             else
             {
                 return false;
             }
         }
     }
     catch
     {
         return false;
     }
 }
Ejemplo n.º 44
0
 public EFUnitOfWork()
 {
     Context = new CustomerEntities();
 }
Ejemplo n.º 45
0
        public string getCustomerForUser(string username)
        {
            try
            {
                using (var db = new CustomerEntities())
                {
                    var userSet = db.Main_UsersSet.Where(o => o.Username.Equals(username)).First();

                    return userSet.Customer;
                }
            }
            catch (Exception ex)
            {
                return "Couldn't get Customer name";
            }
        }
Ejemplo n.º 46
0
        public string getCustomerForUnit(string UnitID)
        {
            try
            {
                using (var db = new CustomerEntities())
                {
                    if (db.Main_Bridge_Customer_UnitSet.Any(o => o.Main_Dim_UnitSet.UnitID.Equals(UnitID)))
                    {
                        var unit = db.Main_Bridge_Customer_UnitSet.Where(x => x.Main_Dim_UnitSet.UnitID.Equals(UnitID)).First();
                        return unit.Main_Dim_CustomerSet.Customer_name;
                    }
                    else
                    {
                        return "Unit not found at customer";
                    }
                }
            }
            catch
            {
                return "Couldn't connect to CustomerEntities";
            }

            //return "gg";
        }