Пример #1
0
        public int FindCustomer(string userName, DateTime DOB)
        {
            using (var context = new connected_usersContext())
            {
                Customers cust = context.Customers.Where(x => x.Name == userName && x.Dob == DOB).SingleOrDefault();

                if (cust != null)
                {
                    Reltionship rela = context.Reltionship.Where(x => x.ChildernId == cust.CustomerId || x.WifeId == cust.CustomerId).SingleOrDefault();
                    if (rela == null)
                    {
                        return(cust.CustomerId);
                    }
                }
                return(-1);
            }
        }
Пример #2
0
        public bool UpdateCustomers(List <CustomerDetails> cust, string loggedInUserRoleId, string userId)
        {
            using (var context = new connected_usersContext())
            {
                foreach (CustomerDetails c in cust)
                {
                    //If dependant user needs to be deleted
                    if (c.DependantToBeDeleted ?? false)
                    {
                        int?        id    = (int?)c.CustomerID;
                        Reltionship cusDe = context.Reltionship.Where(x => x.ChildernId == id || x.WifeId == id).SingleOrDefault();
                        if (cusDe != null)
                        {
                            context.Reltionship.Remove(cusDe);
                            context.SaveChanges();
                        }
                        continue;
                    }
                    //else if (c.CustomerID == -1)  //Add new user
                    //{
                    //    var customer = context.Customers.Add(new Customers()
                    //    {
                    //        Name = c.CutomerName,
                    //        Dob = c.DOB,
                    //        ArabicEducationId = c.arabicEducationID,
                    //        EducationId = c.educationId,
                    //        OccupationId = c.OccupationId,
                    //        MaritalStatusId = c.MaritalStatusId ?? 0,
                    //        GenderId = c.GenderId ?? 0,
                    //        MobileNumber = c.MobileNumber,
                    //        OccupdationDetails = c.OccupationDetails ?? string.Empty,
                    //        EducationDetail = c.EducationDetails ?? string.Empty,
                    //        CreatedBy = Convert.ToInt32(userId),
                    //        CreatedTime = DateTime.Now,
                    //        UpdatedBy = null,
                    //        UpdatedTime = null,


                    //    });
                    //    context.SaveChanges();

                    //    context.CustomerAddress.Add(new CustomerAddress()
                    //    {
                    //        CustomerId = customer.Entity.CustomerId,
                    //        Address1=c.Address1,
                    //        Address2=c.Address2,
                    //        Area=c.Area,
                    //        StateId=c.StateId,
                    //        CityId=c.CityId,
                    //        PinId=c.PinId,
                    //    });
                    //    context.SaveChanges();

                    //    if (c.DependantToBeAddedAsChild ?? false)
                    //    {
                    //        context.Reltionship.Add(new Reltionship()
                    //        {
                    //            UserId = c.DependantParentID ?? 0,
                    //            ChildernId = customer.Entity.CustomerId,
                    //        });
                    //    }
                    //    else
                    //    {
                    //        context.Reltionship.Add(new Reltionship()
                    //        {
                    //            UserId = c.DependantParentID??0,
                    //            WifeId = customer.Entity.CustomerId,
                    //        });
                    //    }
                    //    context.SaveChanges();
                    //}

                    else
                    {
                        Customers custom = context.Customers.Where(x => x.CustomerId == c.CustomerID).Include(x => x.CustomerAddress).SingleOrDefault();
                        custom.ArabicEducationId = c.arabicEducationID ?? 0;
                        custom.EducationId       = c.educationId ?? 0;
                        custom.OccupationId      = c.OccupationId ?? 0;
                        custom.MaritalStatusId   = c.MaritalStatusId ?? 0;
                        custom.GenderId          = c.GenderId ?? 0;
                        if (!string.IsNullOrEmpty(c.MobileNumber))
                        {
                            custom.MobileNumber = c.MobileNumber;
                        }
                        if (!string.IsNullOrEmpty(c.OccupationDetails))
                        {
                            custom.OccupdationDetails = c.OccupationDetails;
                        }
                        if (!string.IsNullOrEmpty(c.EducationDetails))
                        {
                            custom.EducationDetail = c.EducationDetails;
                        }
                        custom.UpdatedBy   = Convert.ToInt32(userId);
                        custom.UpdatedTime = DateTime.Now;
                        if (custom.CustomerAddress != null)
                        {
                            if (!string.IsNullOrEmpty(c.Address1))
                            {
                                custom.CustomerAddress.Address1 = c.Address1;
                            }
                            if (!string.IsNullOrEmpty(c.Address2))
                            {
                                custom.CustomerAddress.Address2 = c.Address2;
                            }
                            if (!string.IsNullOrEmpty(c.Area))
                            {
                                custom.CustomerAddress.Area = c.Area;
                            }
                            custom.CustomerAddress.CityId  = c.CityId;
                            custom.CustomerAddress.StateId = c.StateId;
                            custom.CustomerAddress.PinId   = c.PinId;
                        }

                        context.SaveChanges();

                        if (c.DependantParentID > 0)  //Add existing customer as dependent
                        {
                            Reltionship re = context.Reltionship.Where(x => x.ChildernId == c.CustomerID ||
                                                                       x.WifeId == c.CustomerID || x.UserId == c.CustomerID).SingleOrDefault();

                            if (re == null)
                            {
                                if (c.DependantToBeAddedAsChild ?? false) //add dependent as child
                                {
                                    context.Reltionship.Add(new Reltionship()
                                    {
                                        UserId     = c.DependantParentID ?? 0,
                                        ChildernId = c.CustomerID,
                                    });
                                }
                                else //add dependent as wife
                                {
                                    context.Reltionship.Add(new Reltionship()
                                    {
                                        UserId = c.DependantParentID ?? 0,
                                        WifeId = c.CustomerID,
                                    });
                                }
                            }
                        }
                        context.SaveChanges();
                    }
                }
            }
            return(true);
        }