Esempio n. 1
0
        public CrudStatus AddCustomer(string firstName, string lastName, string custMobile, int State, int City)
        {
            _myshopDb = new MyshopDb();
            Gbl_Master_Customer _newCustomer = new Gbl_Master_Customer();

            _newCustomer.CreatedBy      = WebSession.UserId;
            _newCustomer.CreatedDate    = DateTime.Now;
            _newCustomer.FirstName      = firstName;
            _newCustomer.LastName       = lastName;
            _newCustomer.State          = State;
            _newCustomer.District       = City;
            _newCustomer.IsDeleted      = false;
            _newCustomer.IsSync         = false;
            _newCustomer.Mobile         = custMobile;
            _newCustomer.CustomerTypeId = 1;
            _newCustomer.ShopId         = WebSession.ShopId;
            _myshopDb.Gbl_Master_Customer.Add(_newCustomer);
            return(_myshopDb.SaveChanges() > 0 ? CrudStatus.Inserted : CrudStatus.NoEffect);
        }
Esempio n. 2
0
        public Enums.CrudStatus SetCustomer(CustomerModel model, Enums.CrudType crudType)
        {
            try
            {
                myshop = new MyshopDb();

                var oldCustomer = myshop.Gbl_Master_Customer.Where(cust => (cust.CustomerId.Equals(model.CutomerId) || (cust.Mobile.Equals(model.Mobile.Trim()))) && cust.IsDeleted == false).FirstOrDefault();
                if (oldCustomer != null && oldCustomer.ShopId.Equals(WebSession.ShopId))
                {
                    if (crudType == Enums.CrudType.Update)
                    {
                        oldCustomer.FirstName           = model.FirstName;
                        oldCustomer.MiddleName          = model.MiddleName;
                        oldCustomer.LastName            = model.LastName;
                        oldCustomer.Email               = model.Email;
                        oldCustomer.Address             = model.Address;
                        oldCustomer.State               = model.State;
                        oldCustomer.District            = model.City;
                        oldCustomer.PINCode             = model.PINCode;
                        oldCustomer.IsDeleted           = false;
                        oldCustomer.IsSync              = false;
                        oldCustomer.ModifiedBy          = WebSession.UserId;
                        oldCustomer.ModificationDate    = DateTime.Now;
                        myshop.Entry(oldCustomer).State = EntityState.Modified;
                    }
                    else if (crudType == Enums.CrudType.Delete)
                    {
                        var stock = myshop.Sale_Tr_Invoice.Where(x => x.IsDeleted == false && x.CustomerId.Equals(model.CustomerTypeId)).FirstOrDefault();
                        if (stock == null)
                        {
                            oldCustomer.IsDeleted           = true;
                            oldCustomer.IsSync              = false;
                            oldCustomer.ModifiedBy          = WebSession.UserId;
                            oldCustomer.ModificationDate    = DateTime.Now;
                            myshop.Entry(oldCustomer).State = EntityState.Modified;
                        }
                        else
                        {
                            return(Enums.CrudStatus.AlreadyInUse);
                        }
                    }
                    else
                    {
                        return(Enums.CrudStatus.AlreadyExistForSameShop);
                    }
                }
                else if (crudType == Enums.CrudType.Insert)
                {
                    Gbl_Master_Customer newCustomer = new Gbl_Master_Customer();
                    newCustomer.FirstName           = model.FirstName;
                    newCustomer.MiddleName          = model.MiddleName;
                    newCustomer.LastName            = model.LastName;
                    newCustomer.CustomerTypeId      = model.CustomerTypeId;
                    newCustomer.Mobile              = model.Mobile;
                    newCustomer.Email               = model.Email;
                    newCustomer.Address             = model.Address;
                    newCustomer.State               = model.State;
                    newCustomer.District            = model.City;
                    newCustomer.PINCode             = model.PINCode;
                    newCustomer.IsDeleted           = false;
                    newCustomer.IsSync              = false;
                    newCustomer.ModifiedBy          = WebSession.UserId;
                    newCustomer.ModificationDate    = DateTime.Now;
                    newCustomer.CreatedBy           = WebSession.UserId;
                    newCustomer.CreatedDate         = DateTime.Now;
                    newCustomer.ShopId              = WebSession.ShopId;
                    myshop.Entry(newCustomer).State = EntityState.Added;
                }

                int result = myshop.SaveChanges();
                return(Utility.CrudStatus(result, crudType));
            }
            catch (Exception ex)
            {
                return(Enums.CrudStatus.Exception);
            }
            finally
            {
            }
        }