public CustomerModel AddCustomer(string phonenumber, int storeid, string customername)
        {
            CustomerModel cust = new CustomerModel();

            using (nathusfeedback_androidEntities context = new nathusfeedback_androidEntities())
            {
                customermaster u = new customermaster();
                u.PhoneNumber  = phonenumber;
                u.CustomerName = customername;
                u.StoreId      = storeid;
                u.AdminId      = 1;
                u.Role         = 1;
                //var data = context.customermasters.Where(x => x.PhoneNumber == u.PhoneNumber && x.StoreId == u.StoreId).FirstOrDefault();
                //if (data != null)
                //{
                //    //context.customermasters.Where(p => p.PhoneNumber == u.PhoneNumber && p.StoreId == u.StoreId).ToList().ForEach(x => x.PhoneNumber = u.PhoneNumber);
                //    cust.CustomerId = Convert.ToInt32(data.CustomerId);
                //    //cust.CustomerName = custdata.CustomerName;
                //    //cust.PhoneNumber = custdata.PhoneNumber;
                //    //cust.Role = Convert.ToInt32(custdata.Role);
                //    //cust.CustomerEmailId = cust.CustomerEmailId;
                //    //user.ProfilePictureUrl = "http://103.233.79.234/Data/EverGreen_Android/EverGreenProfilePicture/" + user.LoginID + "ProfilePicture.jpg";
                //}
                //else
                //{
                //context.customermasters.Add(u);
                //}
                context.customermasters.Add(u);
                var result = context.SaveChanges();
                //int id = u.CustomerId;
                if (result > 0)
                {
                    //var custdata = context.customermasters.Where(x => x.CustomerId == u.CustomerId).FirstOrDefault();
                    //if (custdata != null)
                    //{
                    cust.CustomerId = Convert.ToInt32(u.CustomerId);
                    //cust.CustomerName = custdata.CustomerName;
                    //cust.PhoneNumber = custdata.PhoneNumber;
                    //cust.Role = Convert.ToInt32(custdata.Role);
                    //cust.CustomerEmailId = cust.CustomerEmailId;
                    //user.ProfilePictureUrl = "http://103.233.79.234/Data/EverGreen_Android/EverGreenProfilePicture/" + user.LoginID + "ProfilePicture.jpg";
                    //}
                }
            }
            return(cust);
        }
예제 #2
0
 /// <summary>
 /// Create Customer
 /// </summary>
 /// <param name="customerEntity"></param>
 /// <returns></returns>
 public int CreateCustomer(CustomerEntity customerEntity)
 {
     using (var scope = new TransactionScope())
     {
         var customer = new customermaster
         {
             CustomerName = customerEntity.CustomerName,
             ContacntNo   = customerEntity.ContacntNo,
             EmailId      = customerEntity.EmailId,
             GSTIN        = customerEntity.GSTIN,
             PAN          = customerEntity.PAN,
             TIN          = customerEntity.TIN,
             Country      = customerEntity.Country,
             State        = customerEntity.State,
             City         = customerEntity.City,
             Zip          = customerEntity.Zip
         };
         _unitOfWork.CustomerRepository.Insert(customer);
         _unitOfWork.Save();
         scope.Complete();
         return(customer.CustomerID);
     }
 }
예제 #3
0
        public CustomerEventModel AddEventCustomer(CustomerEventModel model)
        {
            CustomerEventModel eventdata = new CustomerEventModel();

            using (evergreenfeedback_androidEntities context = new evergreenfeedback_androidEntities())
            {
                int customerid;
                customereventmaster u = new customereventmaster();
                u.Gathering = model.Gathering;
                u.Time      = model.Time;
                u.Comment   = model.Comment;
                u.StoreId   = model.StoreId;
                u.EventDate = model.EventDate;
                //u.CustomerId = model.CustomerId;
                customermaster c = new customermaster();
                c.CustomerName    = model.Name;
                c.CustomerEmailId = model.Email;
                c.PhoneNumber     = model.Phone;
                c.StoreId         = model.StoreId;
                //var cust = context.customermasters.Where(x=> x.PhoneNumber == model.Phone && x.StoreId == model.StoreId).FirstOrDefault();
                //if (cust != null)
                //{
                //    u.CustomerId = cust.CustomerId;
                //    eventdata.CustomerId = cust.CustomerId;
                //    eventdata.Name = cust.CustomerName;
                //    eventdata.Phone = cust.PhoneNumber;
                //    eventdata.Email = cust.CustomerEmailId;

                //    var eventresult = context.customereventmasters.Where(x => x.StoreId == cust.StoreId && x.CustomerId == cust.CustomerId).FirstOrDefault();
                //    if (eventresult != null)
                //    {
                //        context.Entry(eventresult).State = System.Data.Entity.EntityState.Modified;
                //        context.SaveChanges();
                //        eventdata.CustomerId = (int)eventresult.CustomerId;
                //        eventdata.StoreId = (int)eventresult.StoreId;
                //        eventdata.Gathering = (int)eventresult.Gathering;
                //        eventdata.Comment = eventresult.Comment;
                //        eventdata.EventDate = (DateTime)eventresult.EventDate;
                //        eventdata.Time = eventresult.Time;
                //    }
                //    else
                //    {
                //        context.customereventmasters.Add(u);
                //    }
                //    var result = context.SaveChanges();
                //    if (result > 0)
                //    {
                //        var data = context.customereventmasters.Where(x => x.StoreId == u.StoreId && x.CustomerId == cust.CustomerId).FirstOrDefault();
                //        eventdata.CustomerId = (int)data.CustomerId;
                //        eventdata.StoreId = (int)data.StoreId;
                //        eventdata.Gathering =(int) data.Gathering;
                //        eventdata.Comment = data.Comment;
                //        eventdata.EventDate = (DateTime)data.EventDate;
                //        eventdata.Time = data.Time;

                //    }
                //}
                //else
                //{
                context.customermasters.Add(c);
                //}
                var resultcust = context.SaveChanges();
                var id         = c.CustomerId;
                if (resultcust > 0)
                {
                    var cus = context.customermasters.Where(cs => cs.CustomerId == id).SingleOrDefault();

                    eventdata.CustomerId = cus.CustomerId;
                    eventdata.Name       = cus.CustomerName;
                    eventdata.Phone      = cus.PhoneNumber;
                    eventdata.Email      = cus.CustomerEmailId;
                    eventdata.StoreId    = (int)cus.StoreId;


                    //var eventresult = context.customereventmasters.Where(x => x.StoreId == model.StoreId && x.CustomerId == model.CustomerId).FirstOrDefault();
                    //if (eventresult != null)
                    //{
                    //    context.Entry(eventresult).State = System.Data.Entity.EntityState.Modified;
                    //    context.SaveChanges();

                    //    eventdata.Gathering = (int)eventresult.Gathering;
                    //    eventdata.Comment = eventresult.Comment;
                    //    eventdata.StoreId = (int)eventresult.StoreId;
                    //    eventdata.EventDate = (DateTime)eventresult.EventDate;
                    //    eventdata.Time = eventresult.Time;
                    //}
                    //else
                    //{
                    u.CustomerId = cus.CustomerId;
                    context.customereventmasters.Add(u);
                    //}
                    var result = context.SaveChanges();
                    if (result > 0)
                    {
                        var data = context.customereventmasters.Where(x => x.StoreId == model.StoreId && x.CustomerId == cus.CustomerId).FirstOrDefault();

                        eventdata.Gathering = (int)data.Gathering;
                        eventdata.StoreId   = (int)data.StoreId;
                        eventdata.Comment   = data.Comment;
                        eventdata.EventDate = (DateTime)data.EventDate;
                        eventdata.Time      = data.Time;
                    }
                }
            }
            return(eventdata);
        }