Beispiel #1
0
        public int AddCustomer(CustomerTbl cust, string Customername)
        {
            int returnVal = 0;

            try
            {
                Customername = cust.CustomerName;

                //CustomerTbl existingCustomer = db.CustomerTbl.Where(ct => ct.CustomerName == ct.CustomerName).FirstOrDefault();

                bool existingCustomer = db.CustomerTbl.Any(x => x.CustomerName == Customername);
                if (existingCustomer == true)
                {
                    returnVal = -1;
                }
                if (existingCustomer == false)
                {
                    db.CustomerTbl.Add(cust);
                    db.SaveChanges();
                }

                //return 1;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                //throw;
            }

            return(returnVal);
        }
Beispiel #2
0
 public CustomerTbl GetCustomer(int id)
 {
     try
     {
         CustomerTbl c = db.CustomerTbl.Find(id);
         return(c);
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #3
0
 public int DeleteCustomer(int id)
 {
     try
     {
         CustomerTbl cust = db.CustomerTbl.Find(id);
         db.CustomerTbl.Remove(cust);
         db.SaveChanges();
         return(1);
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #4
0
        public int UpdateCustomer(CustomerTbl cust, int Customerid, string Customername)
        {
            int returnVal = 0;


            try
            {
                //db.Entry(cust).State = EntityState.Modified;
                //db.SaveChanges();

                //return 1;

                Customerid   = cust.CustomerId;
                Customername = cust.CustomerName;

                cust = db.CustomerTbl.FirstOrDefault(x => x.CustomerId == Customerid);

                if (cust != null)
                {
                    cust.CustomerId   = Customerid;
                    cust.CustomerName = Customername;
                    db.CustomerTbl.Update(cust);
                    Customerid   = cust.CustomerId;
                    Customername = cust.CustomerName;
                }

                bool existingCustomer  = db.CustomerTbl.Any(x => x.CustomerName == Customername);
                bool existingCustomer1 = db.CustomerTbl.Any(x => (x.CustomerId == Customerid) && (x.CustomerName == Customername));

                if (existingCustomer1 == true)
                {
                    returnVal = db.SaveChanges();
                }
                else if (existingCustomer == true)
                {
                    returnVal = -1;
                }
                else
                {
                    returnVal = db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                //throw;
            }
            return(returnVal);
        }
        public int AddCustomer(CustomerTbl cust, Customer ct, string Customername, string CustomerNo)
        {
            //List<Customer> Items = new List<Customer>();
            int returnVal = 0;

            //try
            //{
            //    using (var db = new TestDetailContext())
            //    {
            //        Customer get;
            //        foreach (var it in db.CustomerTbl)
            //        {
            //            get = new Customer();
            //            get.CustomerNo = it.CustomerNo;
            //            get.CustomerName = it.CustomerName;
            //            get.CreatedBy = it.CreatedBy;
            //            get.CreatedDate = it.CreatedDate;
            //            Items.Add(get);
            //        }
            //        CustomerTbl Cust;
            //        Cust = new CustomerTbl();
            //        Cust.CustomerNo = cust.CustomerNo;
            //        Cust.CustomerName = cust.CustomerName;
            //        Cust.CreatedBy = "abc";
            //        Cust.CreatedDate = DateTime.Now;
            //        CustomerNo = Cust.CustomerNo;

            //        Customername = cust.CustomerName;
            //        bool existingCustomernumber = db.CustomerTbl.Any(x => x.CustomerNo == cust.CustomerNo);
            //        if (existingCustomernumber == true)
            //        {
            //            returnVal = -2;
            //        }

            //        bool existingCustomer = db.CustomerTbl.Any(x => x.CustomerName == cust.CustomerName);
            //        if (existingCustomer == true)
            //        {
            //            returnVal = -1;
            //        }
            //        if (existingCustomer == false && existingCustomernumber == false)
            //        {
            //            db.CustomerTbl.Add(Cust);
            //            returnVal = db.SaveChanges();


            //        }

            //        return 1;
            //    }
            //}
            //catch (Exception ex)
            //{

            //    throw;
            //}

            try
            {
                Customername     = cust.CustomerName;
                cust.CreatedDate = DateTime.Now;
                if (cust.CreatedDate != null)
                {
                    cust.CreatedBy = "abcd";
                }
                bool existingCustomernumber = db.CustomerTbl.Any(x => x.CustomerNo == cust.CustomerNo);
                if (existingCustomernumber == true)
                {
                    returnVal = -2;
                }

                bool existingCustomer = db.CustomerTbl.Any(x => x.CustomerName == Customername);
                if (existingCustomer == true)
                {
                    returnVal = -1;
                }
                if (existingCustomer == false && existingCustomernumber == false)
                {
                    db.CustomerTbl.Add(cust);
                    db.SaveChanges();
                }

                //return 1;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                //throw;
            }



            return(returnVal);
        }