Ejemplo n.º 1
0
        public JsonResult GetRandomPassword()
        {
            PickupRequestDAO _dao  = new PickupRequestDAO();
            string           passw = _dao.RandomPassword(6);

            return(Json(new { data = passw }, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public ActionResult ForgotPassword(UserLoginVM vm)
        {
            string emailid = vm.UserName;
            var    _user   = db.UserRegistrations.Where(cc => cc.UserName == emailid).FirstOrDefault();

            if (_user != null)
            {
                PickupRequestDAO _dao        = new PickupRequestDAO();
                string           newpassword = _dao.RandomPassword(6);

                _user.Password        = newpassword;
                db.Entry(_user).State = EntityState.Modified;
                db.SaveChanges();
                EmailDAO _emaildao = new EmailDAO();
                _emaildao.SendForgotMail(_user.UserName, "User", newpassword);
                TempData["SuccessMsg"] = "Reset Password Details are sent,Check Email!";

                return(RedirectToAction("Home", "Home"));
                //return Json(new { status = "ok", message = "Reset Password Details are sent,Check Email" }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                Session["ForgotStatus"]  = "Forgot";
                Session["StatusMessage"] = "Invalid EmailId!";
                return(RedirectToAction("Home", "Home"));
                //return Json(new { status = "Failed", message = "Invalid EmailId!" }, JsonRequestBehavior.AllowGet);
            }
        }
        public ActionResult Create()
        {
            var transtypes = new SelectList(new[]
            {
                new { ID = "Cr", trans = "Credit" },
                new { ID = "Dr", trans = "Debit" },
            },
                                            "ID", "trans", 1);



            ViewBag.businessType = db.BusinessTypes.ToList();
            ViewBag.country      = db.CountryMasters.ToList();
            ViewBag.city         = db.CityMasters.ToList();
            ViewBag.location     = db.LocationMasters.ToList();
            ViewBag.currency     = db.CurrencyMasters.ToList();
            ViewBag.employee     = db.EmployeeMasters.ToList();
            ViewBag.roles        = db.RoleMasters.ToList();
            int branchid = Convert.ToInt32(Session["CurrentBranchID"].ToString());

            PickupRequestDAO doa = new PickupRequestDAO();

            ViewBag.CustomerNo = doa.GetMaxCustomerCode(branchid);
            CustmorVM obj = new CustmorVM();

            obj.RoleID   = 13;
            obj.Password = doa.RandomPassword(6);
            return(View(obj));
        }
        public ActionResult Create(int id = 0)
        {
            var transtypes = new SelectList(new[]
            {
                new { ID = "Cr", trans = "Credit" },
                new { ID = "Dr", trans = "Debit" },
            },
                                            "ID", "trans", 1);



            ViewBag.businessType = db.BusinessTypes.ToList();
            ViewBag.country      = db.CountryMasters.ToList();
            ViewBag.city         = db.CityMasters.ToList();
            ViewBag.location     = db.LocationMasters.ToList();
            ViewBag.currency     = db.CurrencyMasters.ToList();
            ViewBag.employee     = db.EmployeeMasters.ToList();
            ViewBag.roles        = db.RoleMasters.ToList();
            int BranchID = Convert.ToInt32(Session["CurrentBranchID"].ToString());
            var data     = db.tblDepots.Where(c => c.BranchID == BranchID).ToList();

            ViewBag.Depot = data;

            int branchid = Convert.ToInt32(Session["CurrentBranchID"].ToString());

            ViewBag.UserRoleId = Convert.ToInt32(Session["UserRoleID"].ToString());
            CustmorVM obj = new CustmorVM();

            if (id == 0)
            {
                ViewBag.Title = "Customer - Create";
                PickupRequestDAO doa = new PickupRequestDAO();
                ViewBag.CustomerNo = "";// doa.GetMaxCustomerCode(branchid);
                obj.CustomerID     = 0;
                obj.RoleID         = 13;
                obj.CustomerType   = "CS";

                obj.Password         = doa.RandomPassword(6);
                obj.ApprovedBy       = Convert.ToInt32(Session["UserID"]);
                obj.ApprovedUserName = Convert.ToString(Session["UserName"]);
                obj.CurrenceyID      = Convert.ToInt32(Session["CurrencyId"].ToString());
            }
            else
            {
                ViewBag.Title = "Customer - Modify";
                obj           = GetDetail(id);
            }

            return(View(obj));
        }
Ejemplo n.º 5
0
        public ActionResult Edit(EmployeeVM a)
        {
            UserRegistration u       = new UserRegistration();
            PickupRequestDAO _dao    = new PickupRequestDAO();
            int            BranchID  = Convert.ToInt32(Session["CurrentBranchID"].ToString());
            int            companyid = Convert.ToInt32(Session["CurrentCompanyID"].ToString());
            EmployeeMaster v         = new EmployeeMaster();

            v = db.EmployeeMasters.Find(a.EmployeeID);

            v.EmployeeName = a.EmployeeName;
            v.EmployeeCode = a.EmployeeCode;
            v.Address1     = a.Address1;
            v.Address2     = a.Address2;
            v.Address3     = a.Address3;
            v.Phone        = a.Phone;
            //v.Email = a.Email;
            v.Fax           = a.Fax;
            v.Mobile        = a.MobileNo;
            v.CountryName   = a.CountryName;
            v.AcCompanyID   = companyid;
            v.DesignationID = a.DesignationID;


            v.BranchID = BranchID;
            v.DepotID  = a.Depot;
            //if (v.Password!=a.Password)
            //   v.Password = a.Password;
            v.MobileDeviceID   = a.MobileDeviceID;
            v.MobileDevicePwd  = a.MobileDevicePWD;
            v.JoinDate         = a.JoinDate;
            v.StatusCommission = a.StatusCommision;
            v.statusDefault    = a.StatusDefault;
            v.StatusActive     = a.StatusActive;

            UserRegistration x = null;

            if (a.UserID != null && a.UserID > 0)
            {
                x = (from b in db.UserRegistrations where b.UserID == a.UserID select b).FirstOrDefault();
            }

            if (v.Email != a.Email)
            {
                if (x == null)
                {
                    int max1 = (from c1 in db.UserRegistrations orderby c1.UserID descending select c1.UserID).FirstOrDefault();

                    int roleid = db.RoleMasters.Where(t => t.RoleName == "Agent").FirstOrDefault().RoleID;
                    u.UserID   = max1 + 1;
                    u.UserName = a.Email;
                    u.EmailId  = a.Email;
                    if (a.Password == "")
                    {
                        u.Password = _dao.RandomPassword(6);
                    }
                    else
                    {
                        u.Password = a.Password; //  _dao.RandomPassword(6);
                    }
                    u.Phone    = a.Phone;
                    u.IsActive = true;
                    u.RoleID   = roleid;
                    db.UserRegistrations.Add(u);
                    db.SaveChanges();

                    v.Email  = a.Email;
                    a.UserID = u.UserID;
                }
                else
                {
                    //checking duplicate
                    UserRegistration x1 = (from b in db.UserRegistrations where b.UserName == a.Email && b.UserID != a.UserID select b).FirstOrDefault();
                    if (x1 == null)
                    {
                        x.EmailId = a.Email;
                        if (a.Password == "")
                        {
                            x.Password = _dao.RandomPassword(6);
                        }
                        else
                        {
                            x.Password = a.Password; //  _dao.RandomPassword(6);
                        }
                        db.Entry(x).State = EntityState.Modified;
                        db.SaveChanges();
                    }

                    v.Email  = a.Email;
                    a.UserID = x.UserID;
                }
            }
            else
            {
                if (a.UserID == null || a.UserID == 0)
                {
                    int max1 = (from c1 in db.UserRegistrations orderby c1.UserID descending select c1.UserID).FirstOrDefault();

                    int roleid = db.RoleMasters.Where(t => t.RoleName == "Agent").FirstOrDefault().RoleID;
                    u.UserID   = max1 + 1;
                    u.UserName = a.Email;
                    u.EmailId  = a.Email;

                    if (a.Password == "")
                    {
                        u.Password = _dao.RandomPassword(6);
                    }
                    else
                    {
                        u.Password = a.Password; //  _dao.RandomPassword(6);
                    }
                    u.Phone    = a.Phone;
                    u.IsActive = true;
                    u.RoleID   = a.RoleID;
                    db.UserRegistrations.Add(u);
                    db.SaveChanges();

                    v.UserID = u.UserID;
                }
                else
                {
                    u = (from b in db.UserRegistrations where b.UserID == a.UserID select b).FirstOrDefault();
                    if (u.Password != a.Password)
                    {
                        u.Password = a.Password;
                    }

                    if (u.RoleID != a.RoleID)
                    {
                        u.RoleID = a.RoleID;
                    }
                    if (u.Password == null)
                    {
                        u.Password = "******";
                    }
                    db.Entry(u).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }



            db.Entry(v).State = EntityState.Modified;
            db.SaveChanges();
            TempData["SuccessMsg"] = "You have successfully Update Employee.";
            return(RedirectToAction("Index"));
        }
        public ActionResult Create(CustmorVM c)
        {
            string locationname = c.LocationName;
            string country      = c.CountryName;
            string city         = c.CityName;


            CustomerMaster   obj  = new CustomerMaster();
            PickupRequestDAO _dao = new PickupRequestDAO();

            if (c.CustomerID == 0)
            {
                int max         = (from d in db.CustomerMasters orderby d.CustomerID descending select d.CustomerID).FirstOrDefault();
                int accompanyid = Convert.ToInt32(Session["CurrentCompanyID"].ToString());
                int branchid    = Convert.ToInt32(Session["CurrentBranchID"].ToString());
                obj.CustomerID  = max + 1;
                obj.AcCompanyID = accompanyid;

                obj.CustomerCode = c.CustomerCode; //  _dao.GetMaxCustomerCode(branchid); // c.CustomerCode;
            }
            else
            {
                obj = db.CustomerMasters.Find(c.CustomerID);
            }
            obj.CustomerName = c.CustomerName;
            obj.CustomerType = c.CustomerType;

            obj.ReferenceCode = c.ReferenceCode;
            obj.ContactPerson = c.ContactPerson;
            obj.Address1      = c.Address1;
            obj.Address2      = c.Address2;
            obj.Address3      = c.Address3;
            obj.Phone         = c.Phone;
            obj.Mobile        = c.Mobile;
            obj.Fax           = c.Fax;
            obj.Email         = c.Email;
            obj.WebSite       = c.Website;
            obj.CountryID     = c.CountryID;
            if (c.CityID == 0)
            {
                obj.CityID = null;
            }
            else
            {
                obj.CityID = c.CityID;
            }
            if (c.LocationID == 0)
            {
                obj.LocationID = null;
            }
            else
            {
                obj.LocationID = c.LocationID;
            }
            obj.CountryName  = c.CountryName;
            obj.CityName     = c.CityName;
            obj.LocationName = c.LocationName;
            if (c.CurrenceyID == 0)
            {
                c.CurrenceyID = Convert.ToInt32(Session["CurrencyId"].ToString());
            }
            else
            {
                obj.CurrencyID = c.CurrenceyID;
            }
            obj.StatusActive     = c.StatusActive;
            obj.CreditLimit      = c.CreditLimit;
            obj.StatusTaxable    = c.StatusTaxable;
            obj.EmployeeID       = c.EmployeeID;
            obj.statusCommission = c.StatusCommission;
            obj.VATTRN           = c.VATTRN;

            obj.CourierServiceID = c.CourierServiceID;
            obj.BranchID         = Convert.ToInt32(Session["CurrentBranchID"].ToString());
            obj.CustomerUsername = c.CustomerUsername;
            //obj.Password = c.Password;
            obj.Password        = _dao.RandomPassword(6);
            obj.BusinessTypeId  = c.BusinessTypeId;
            obj.Referal         = c.Referal;
            obj.OfficeOpenTime  = c.OfficeTimeFrom;
            obj.OfficeCloseTime = c.OfficeTimeTo;
            if (c.DepotID == null)
            {
                obj.DepotID = Convert.ToInt32(Session["CurrentDepotID"].ToString());
            }
            else
            {
                obj.DepotID = c.DepotID;
            }

            if (c.CustomerType == "CR" && c.ChkApprovedBy)
            {
                obj.ApprovedBy = Convert.ToInt32(Session["UserID"]);
                obj.ApprovedOn = c.ApprovedOn;
            }

            //UserRegistration u = new UserRegistration();
            //if (c.Email != null)
            //{
            //    if (c.Email != "")
            //    {

            //        UserRegistration x = (from a in db.UserRegistrations where a.UserName == c.Email select a).FirstOrDefault();
            //        if (x == null)
            //        {

            //            int max1 = (from c1 in db.UserRegistrations orderby c1.UserID descending select c1.UserID).FirstOrDefault();
            //            u.UserID = max1 + 1;
            //            u.UserName = c.Email;
            //            u.EmailId = c.Email;
            //            u.Password = obj.Password;
            //            u.Phone = c.Phone;
            //            u.IsActive = true;
            //            u.RoleID = c.RoleID;


            //        }
            //        try
            //        {
            //            db.UserRegistrations.Add(u);
            //            db.SaveChanges();
            //        }
            //        catch (DbEntityValidationException e)
            //        {
            //            foreach (var eve in e.EntityValidationErrors)
            //            {
            //                Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
            //                    eve.Entry.Entity.GetType().Name, eve.Entry.State);
            //                foreach (var ve in eve.ValidationErrors)
            //                {
            //                    Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
            //                        ve.PropertyName, ve.ErrorMessage);
            //                }

            //            }
            //        }
            //    }
            //}

            try
            {
                //  obj.UserID = u.UserID;
                if (c.CustomerID > 0)
                {
                    db.Entry(obj).State = EntityState.Modified;
                    db.SaveChanges();
                }
                else
                {
                    db.CustomerMasters.Add(obj);
                    db.SaveChanges();
                    ReceiptDAO.ReSaveCustomerCode();
                }


                if (c.EmailNotify == true)
                {
                    EmailDAO _emaildao = new EmailDAO();
                    _emaildao.SendCustomerEmail(c.Email, c.CustomerName, obj.Password);
                }
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
            }


            TempData["SuccessMsg"] = "You have successfully added Customer.";
            return(RedirectToAction("Index"));



            return(View());
        }
Ejemplo n.º 7
0
        public ActionResult Edit(AgentVM item)
        {
            UserRegistration u    = new UserRegistration();
            PickupRequestDAO _dao = new PickupRequestDAO();
            int BranchID          = Convert.ToInt32(Session["CurrentBranchID"].ToString());
            int accompanyid       = Convert.ToInt32(Session["CurrentCompanyID"].ToString());

            AgentMaster a = db.AgentMasters.Find(item.ID);

            a.AcCompanyID   = accompanyid;
            a.Name          = item.AgentName;
            a.AgentCode     = item.AgentCode;
            a.Address1      = item.Address1;
            a.Address2      = item.Address2;
            a.Address3      = item.Address3;
            a.Phone         = item.Phone;
            a.Fax           = item.Fax;
            a.WebSite       = item.WebSite;
            a.ContactPerson = item.ContactPerson;
            a.CountryName   = item.CountryName;
            a.CityName      = item.CityName;
            a.LocationName  = item.LocationName;
            a.CurrencyID    = item.CurrencyID;
            // a.ZoneCategoryID = item.ZoneCategoryID;
            //a.AcHeadID = item.AcHeadID;
            a.CreditLimit = item.CreditLimit;
            a.AgentType   = item.AgentType;

            if (item.StatusActive != null)
            {
                a.StatusActive = Convert.ToBoolean(item.StatusActive);
            }
            if (a.BranchID == null)
            {
                a.BranchID = BranchID;
            }

            UserRegistration x = null;

            if (a.UserID != null && a.UserID > 0)
            {
                x = (from b in db.UserRegistrations where b.UserID == a.UserID select b).FirstOrDefault();
            }

            if (a.Email != item.Email || x == null)
            {
                if (x == null)
                {
                    int max1 = (from c1 in db.UserRegistrations orderby c1.UserID descending select c1.UserID).FirstOrDefault();

                    int roleid = db.RoleMasters.Where(t => t.RoleName == "Agent").FirstOrDefault().RoleID;
                    u.UserID   = max1 + 1;
                    u.UserName = item.Email;
                    u.EmailId  = item.Email;

                    if (item.Password == "" || item.Password == null)
                    {
                        u.Password = _dao.RandomPassword(6);
                    }
                    else
                    {
                        u.Password = item.Password;
                    }
                    u.Phone    = item.Phone;
                    u.IsActive = true;
                    u.RoleID   = roleid;
                    db.UserRegistrations.Add(u);
                    db.SaveChanges();

                    a.Email  = item.Email;
                    a.UserID = u.UserID;
                }
                else
                {
                    //checking duplicate
                    UserRegistration x1 = (from b in db.UserRegistrations where b.UserName == item.Email && b.UserID != a.UserID select b).FirstOrDefault();
                    if (x1 == null)
                    {
                        x.EmailId = item.Email;
                        if (item.Password == "")
                        {
                            x.Password = _dao.RandomPassword(6);
                        }
                        else
                        {
                            x.Password = item.Password;
                        }

                        db.Entry(x).State = EntityState.Modified;
                        db.SaveChanges();
                    }

                    a.Email  = item.Email;
                    a.UserID = x.UserID;
                }
            }
            else
            {
                if (a.UserID == null || a.UserID == 0)
                {
                    int max1 = (from c1 in db.UserRegistrations orderby c1.UserID descending select c1.UserID).FirstOrDefault();

                    int roleid = db.RoleMasters.Where(t => t.RoleName == "Agent").FirstOrDefault().RoleID;
                    u.UserID   = max1 + 1;
                    u.UserName = item.Email;
                    u.EmailId  = item.Email;
                    if (item.Password == "")
                    {
                        u.Password = _dao.RandomPassword(6);
                    }
                    else
                    {
                        u.Password = item.Password;
                    }
                    u.Phone    = item.Phone;
                    u.IsActive = true;
                    u.RoleID   = roleid;
                    db.UserRegistrations.Add(u);
                    db.SaveChanges();
                    a.UserID = u.UserID;
                }
                else
                {
                    u = (from b in db.UserRegistrations where b.UserID == a.UserID select b).FirstOrDefault();
                    if (item.Password != u.Password)
                    {
                        u.Password = item.Password;
                    }

                    db.Entry(u).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }



            if (ModelState.IsValid)
            {
                db.Entry(a).State = EntityState.Modified;
                db.SaveChanges();

                if (item.EmailNotify == true)
                {
                    EmailDAO _emaildao = new EmailDAO();
                    _emaildao.SendCustomerEmail(item.Email, item.Email, u.Password);
                }
                TempData["SuccessMsg"] = "You have successfully Updated Agent.";
                return(RedirectToAction("Index"));
            }
            return(View());
        }
Ejemplo n.º 8
0
        public ActionResult Create(AgentVM item)
        {
            int              companyId = Convert.ToInt32(Session["CurrentCompanyID"].ToString());
            int              BranchID  = Convert.ToInt32(Session["CurrentBranchID"].ToString());
            int?             max       = (from c in db.AgentMasters orderby c.AgentID descending select c.AgentID).FirstOrDefault();
            AgentMaster      a         = new AgentMaster();
            PickupRequestDAO _dao      = new PickupRequestDAO();
            int              roleid    = db.RoleMasters.Where(t => t.RoleName == "Agent").FirstOrDefault().RoleID;

            UserRegistration u = new UserRegistration();

            UserRegistration x = (from b in db.UserRegistrations where b.UserName == item.Email select b).FirstOrDefault();

            if (x == null)
            {
                int max1 = (from c1 in db.UserRegistrations orderby c1.UserID descending select c1.UserID).FirstOrDefault();

                u.UserID   = max1 + 1;
                u.UserName = item.Email;
                u.EmailId  = item.Email;

                if (item.Password == null)
                {
                    u.Password = _dao.RandomPassword(6);
                }
                else
                {
                    u.Password = item.Password;
                }

                u.Phone    = item.Phone;
                u.IsActive = true;
                u.RoleID   = roleid;
                db.UserRegistrations.Add(u);
                db.SaveChanges();
            }

            if (max == null || max == 0)
            {
                a.AgentID       = 1;
                a.Name          = item.AgentName;
                a.AgentCode     = item.AgentCode;
                a.Address1      = item.Address1;
                a.Address2      = item.Address2;
                a.Address3      = item.Address3;
                a.Phone         = item.Phone;
                a.Fax           = item.Fax;
                a.WebSite       = item.WebSite;
                a.ContactPerson = item.ContactPerson;
                a.AcCompanyID   = companyId;
                //a.CountryID = item.CountryID;
                //a.CityID = item.CityID;
                //a.LocationID = item.LocationID;
                a.CurrencyID     = item.CurrencyID;
                a.ZoneCategoryID = item.ZoneCategoryID;
                a.AcHeadID       = item.AcHeadID;
                a.CreditLimit    = item.CreditLimit;
                a.CountryName    = item.CountryName;
                a.CityName       = item.CityName;
                a.LocationName   = item.LocationName;
                a.Email          = item.Email;
                a.Password       = "";
                a.AgentType      = item.AgentType;
                a.UserID         = u.UserID;

                if (item.StatusActive == null)
                {
                    a.StatusActive = false;
                }
                else
                {
                    a.StatusActive = Convert.ToBoolean(item.StatusActive);
                }

                a.BranchID = BranchID;
            }
            else
            {
                a.AgentID        = Convert.ToInt32(max) + 1;
                a.Name           = item.AgentName;
                a.AgentCode      = item.AgentCode;
                a.Address1       = item.Address1;
                a.Address2       = item.Address2;
                a.Address3       = item.Address3;
                a.Phone          = item.Phone;
                a.Fax            = item.Fax;
                a.WebSite        = item.WebSite;
                a.ContactPerson  = item.ContactPerson;
                a.AcCompanyID    = companyId;
                a.CountryName    = item.CountryName;
                a.CityName       = item.CityName;
                a.LocationName   = item.LocationName;
                a.CurrencyID     = item.CurrencyID;
                a.ZoneCategoryID = item.ZoneCategoryID;
                a.AcHeadID       = item.AcHeadID;
                a.CreditLimit    = item.CreditLimit;

                a.Email     = item.Email;
                a.Password  = "";
                a.AgentType = item.AgentType;
                a.UserID    = u.UserID;
                a.BranchID  = BranchID;
                if (item.StatusActive == null)
                {
                    a.StatusActive = false;
                }
                else
                {
                    a.StatusActive = Convert.ToBoolean(item.StatusActive);
                }
            }

            try
            {
                db.AgentMasters.Add(a);
                db.SaveChanges();

                if (item.EmailNotify == true)
                {
                    EmailDAO _emaildao = new EmailDAO();
                    _emaildao.SendCustomerEmail(item.Email, item.Email, u.Password);
                }

                TempData["SuccessMsg"] = "You have successfully added Agent.";
                return(RedirectToAction("Index"));
            }

            catch (Exception ex)
            {
                ViewBag.currency       = db.CurrencyMasters.ToList();
                ViewBag.zonecategory   = db.ZoneCategories.ToList();
                ViewBag.achead         = db.AcHeads.ToList();
                ViewBag.roles          = db.RoleMasters.ToList();
                TempData["WarningMsg"] = ex.Message;
                return(View(item));
            }
        }