public ActionResult DeleteConfirmed(int id)
        {
            UserPermissionAction("states", RoleAction.delete.ToString());
            CheckPermission();

            string StateName = "";

            try
            {
                State tbState = _StateService.GetState(id);
                StateName = tbState.StateName;
                _StateService.DeleteState(tbState);

                TempData["ShowMessage"] = "success";
                TempData["MessageBody"] = tbState.StateName + " is deleted successfully.";
            }
            catch (Exception ex)
            {
                if (CommonCls.ErrorLog(ex.InnerException.InnerException.Message.ToString()) == "fk")
                {
                    TempData["ShowMessage"] = "error";
                    TempData["MessageBody"] = "Alert! cannot delete " + StateName + ". " + StateName + " is used in other forms as well.";
                }
                else
                {
                    TempData["ShowMessage"] = "error";
                    TempData["MessageBody"] = "Some issue occured while proccessing delete operation.";
                }
            }

            return(RedirectToAction("Index", new { operation = "delete", ShowMessage = TempData["ShowMessage"], MessageBody = TempData["MessageBody"] }));
        }
Beispiel #2
0
        public ActionResult RevokePermission(int RoleId)
        {
            UserPermissionAction("role", RoleAction.delete.ToString());
            //Check User Permission
            CheckPermission();

            try
            {
                List <RoleDetail> roleList = _RoleDetailService.GetRoleDetails().Where(z => z.RoleId == RoleId).ToList();
                foreach (RoleDetail role in roleList)
                {
                    _RoleDetailService.DeleteRoleDetail(role);
                }
                TempData["ShowMessage"] = "success";
                TempData["MessageBody"] = "Permission revoked successfully.";
            }
            catch (Exception ex)
            {
                if (CommonCls.ErrorLog(ex.InnerException.InnerException.Message.ToString()) == "fk")
                {
                    TempData["ShowMessage"] = "error";
                    TempData["MessageBody"] = "This is used in another pages.";
                }
                else
                {
                    TempData["ShowMessage"] = "error";
                    TempData["MessageBody"] = "Some problem occured while proccessing on revoke operation.";
                }
            }
            return(RedirectToAction("Index", "Role"));
        }
Beispiel #3
0
        // POST: /User/Delete/5

        public ActionResult DeleteConfirmed(int id, User us)
        {
            UserPermissionAction("user", RoleAction.delete.ToString());
            CheckPermission();

            string UserName = "";

            try
            {
                User user = _UserService.GetUserById(id);//db.Users.Find(id);
                UserName = user.UserName;
                _UserService.DeleteUser(user);

                TempData["ShowMessage"] = "success";
                TempData["MessageBody"] = UserName + " is deleted successfully.";
            }
            catch (Exception ex)
            {
                if (CommonCls.ErrorLog(ex.InnerException.InnerException.Message.ToString()) == "fk")
                {
                    TempData["ShowMessage"] = "error";
                    TempData["MessageBody"] = "" + UserName + " cannot be deleted." + UserName + " is used in other pages.";
                }

                else
                {
                    TempData["ShowMessage"] = "error";
                    TempData["MessageBody"] = "Some problem occured while proccessing delete operation on " + UserName + " user.";
                }
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            UserPermissionAction("company", RoleAction.delete.ToString());
            CheckPermission();
            string CompanyName = "";
            string LogoPath    = "";

            try
            {
                //Delete from Main Table
                Company company = _CompanyService.GetCompany(id);
                CompanyName = company.CompanyName;

                if (Convert.ToInt32(Session["CompanyID"].ToString()) != id)
                {
                    LogoPath = company.LogoPath;
                    _CompanyService.DeleteCompany(company);
                    //db.tbCompanies.Remove(tbcompany);
                    //db.SaveChanges();

                    if (LogoPath != "")
                    {
                        //Delete Logo from folder
                        string   pathDel = Server.MapPath(LogoPath);
                        FileInfo objfile = new FileInfo(pathDel);
                        if (objfile.Exists) //check file exsit or not
                        {
                            objfile.Delete();
                        }
                        //End :Delete Logo from folder
                    }

                    TempData["ShowMessage"] = "success";
                    TempData["MessageBody"] = CompanyName + " is deleted successfully.";
                    //End : Delete from Main Table
                }
                else
                {
                    TempData["ShowMessage"] = "error";
                    TempData["MessageBody"] = "Please switch to another company to delete " + CompanyName + " company.";
                }
            }
            catch (Exception ex)
            {
                if (CommonCls.ErrorLog(ex.InnerException.InnerException.Message.ToString()) == "fk")
                {
                    TempData["ShowMessage"] = "error";
                    TempData["MessageBody"] = "This   " + CompanyName + " is used in another pages.";
                }
                else
                {
                    TempData["ShowMessage"] = "error";
                    TempData["MessageBody"] = "Some problem occured while proccessing delete operation on " + CompanyName + " Company.";
                }
            }

            return(RedirectToAction("Index"));
        }
Beispiel #5
0
        public ActionResult Delete(int?id)
        {
            UserPermissionAction("role", RoleAction.delete.ToString());
            //Check User Permission
            CheckPermission();

            string RoleName = "";

            try
            {
                // RoleModel role = _usersContext.Roles.Where(z => z.RoleId == id).FirstOrDefault();
                Role role = _RoleService.GetRoles().Where(c => c.RoleId == id).FirstOrDefault();



                RoleName = role.RoleName;

                _RoleService.DeleteRole(role);

                TempData["ShowMessage"] = "success";
                TempData["MessageBody"] = RoleName + " is deleted successfully.";
            }
            catch (Exception ex)
            {
                if (CommonCls.ErrorLog(ex.InnerException.InnerException.Message.ToString()) == "fk")
                {
                    TempData["ShowMessage"] = "error";
                    TempData["MessageBody"] = "This role " + RoleName + " is used in another pages.";
                    TempData["MessageBody"] = "" + RoleName + " cannot be deleted." + RoleName + " is used in other pages.";
                }
                else
                {
                    TempData["ShowMessage"] = "error";
                    TempData["MessageBody"] = "Some problem occured while proccessing delete operation on " + RoleName + " role.";
                }
            }
            return(RedirectToAction("Index", "Role"));
        }
Beispiel #6
0
        public ActionResult Delete(int Id)
        {
            UserPermissionAction("supplier", RoleAction.create.ToString());
            CheckPermission();
            try
            {
                var Supplier = _SupplierService.GetSupplier(Id);
                if (Supplier != null)
                {
                    _SupplierService.DeleteSupplier(Supplier);
                }
                TempData["ShowMessage"] = "Success";
                TempData["MessageBody"] = "Record successfully deleted.";
            }
            catch (Exception ex)
            {
                CommonCls.ErrorLog(ex.ToString());
                TempData["ShowMessage"] = "Error";
                TempData["MessageBody"] = "Please fill the required data.";
            }

            return(RedirectToAction("Index"));
        }
        public ActionResult Edit([Bind(Include = "AdminStaffId,CustomerId,TrebId,WebsiteUrl,ApplicationID,Password,CompanyID,UserId,PhotoPath,FirstName,LastName,MiddleName,EmailID,MobileNo,Address,CountryID,StateID,CityID,ZipCode,Latitude,Longitude,CreatedOn,LastUpdatedOn,MobileVerifyCode,EmailVerifyCode,IsMobileVerified,IsEmailVerified,IsActive")] AdminStaffModel AdminStaffModel, HttpPostedFileBase file)
        {
            UserPermissionAction("property", RoleAction.view.ToString());
            CheckPermission();
            TempData["ShowMessage"] = "";
            TempData["MessageBody"] = "";
            try
            {
                if (ModelState.IsValid)
                {
                    var CustomerFound = _CustomerService.GetCustomers().Where(c => ((c.EmailId.Trim() == AdminStaffModel.EmailId.Trim() || c.MobileNo.Trim() == AdminStaffModel.MobileNo.Trim()) && c.CustomerId != AdminStaffModel.CustomerId)).FirstOrDefault();
                    if (CustomerFound == null)
                    {
                        var PhotoPath        = "";
                        var AdminStaffUpdate = _AdminStaffService.GetAdminStaff(AdminStaffModel.AdminStaffId);//.Where(c => c.CustomerId == AdminModel.CustomerId).FirstOrDefault();
                        if (AdminStaffUpdate.PhotoPath != null && AdminStaffUpdate.PhotoPath != "")
                        {
                            PhotoPath = AdminStaffUpdate.PhotoPath;
                        }
                        if (AdminStaffUpdate != null)
                        {
                            // PhotoPath = CustomerUpdate.PhotoPath;
                            if (file != null)
                            {
                                if (AdminStaffUpdate.PhotoPath != "")
                                {   //Delete Old Image
                                    string pathDel = Server.MapPath("~/CustomerPhoto");

                                    FileInfo objfile = new FileInfo(pathDel);
                                    if (objfile.Exists) //check file exsit or not
                                    {
                                        objfile.Delete();
                                    }
                                    //End :Delete Old Image
                                }

                                //Save the photo in Folder
                                var    fileExt  = Path.GetExtension(file.FileName);
                                string fileName = Guid.NewGuid() + fileExt;
                                var    subPath  = Server.MapPath("~/CustomerPhoto");

                                //Check SubPath Exist or Not
                                if (!Directory.Exists(subPath))
                                {
                                    Directory.CreateDirectory(subPath);
                                }
                                //End : Check SubPath Exist or Not

                                var path = Path.Combine(subPath, fileName);
                                file.SaveAs(path);

                                PhotoPath = CommonCls.GetURL() + "/CustomerPhoto/" + fileName;
                            }

                            AdminStaffUpdate.PhotoPath  = PhotoPath;
                            AdminStaffUpdate.FirstName  = AdminStaffModel.FirstName;
                            AdminStaffUpdate.LastName   = AdminStaffModel.LastName;
                            AdminStaffUpdate.Address    = AdminStaffModel.Address;
                            AdminStaffUpdate.EmailId    = AdminStaffModel.EmailId;
                            AdminStaffUpdate.DOB        = AdminStaffModel.DOB;
                            AdminStaffUpdate.WebsiteUrl = AdminStaffModel.WebsiteUrl;
                            AdminStaffUpdate.MobileNo   = AdminStaffModel.MobileNo;
                            if (AdminStaffModel.IsActive == true)
                            {
                                AdminStaffUpdate.IsActive = true;
                            }
                            else
                            {
                                AdminStaffUpdate.IsActive = false;
                            }

                            if (AdminStaffModel.Designation != null && AdminStaffModel.Designation != "")
                            {
                                AdminStaffUpdate.Designation = AdminStaffModel.Designation;
                            }
                            _AdminStaffService.UpdateAdminStaff(AdminStaffUpdate);
                            TempData["ShowMessage"] = "success";
                            TempData["MessageBody"] = AdminStaffUpdate.FirstName + " is update successfully.";
                            return(RedirectToAction("Index", "AdminStaff"));
                        }
                        else
                        {
                            TempData["ShowMessage"] = "error";
                            TempData["MessageBody"] = "User not found.";
                            return(RedirectToAction("Index", "AdminStaff"));
                        }
                    }
                    else
                    {
                        TempData["ShowMessage"] = "error";

                        if (CustomerFound.EmailId.Trim() == AdminStaffModel.EmailId.Trim())
                        {
                            TempData["MessageBody"] = AdminStaffModel.EmailId + " is already exists.";
                        }
                        if (CustomerFound.MobileNo.Trim() == AdminStaffModel.MobileNo.Trim())
                        {
                            TempData["MessageBody"] = "This" + " " + AdminStaffModel.MobileNo + " is already exists.";
                        }
                        else
                        {
                            TempData["MessageBody"] = "Please fill the required field with valid data";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CommonCls.ErrorLog(ex.ToString());
                TempData["ShowMessage"] = "error";
                TempData["MessageBody"] = "Some unknown problem occured while proccessing save operation on " + AdminStaffModel.FirstName + " client";
            }
            var errors           = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray();
            var modelStateErrors = this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors);

            return(View(AdminStaffModel));
        }
        public ActionResult Create(EventModel EventModel, HttpPostedFileBase file)
        {
            UserPermissionAction("event", RoleAction.view.ToString());
            CheckPermission();
            TempData["ShowMessage"] = "";
            TempData["MessageBody"] = "";
            try
            {
                if (ModelState.IsValid)
                {
                    if (string.IsNullOrEmpty(EventModel.EventDate.ToString()))
                    {
                        TempData["ShowMessage"] = "error";
                        TempData["MessageBody"] = "Please select a valid Event Date.";
                        return(View("Create", EventModel));
                    }

                    if (string.IsNullOrEmpty(EventModel.EventName))
                    {
                        TempData["ShowMessage"] = "error";
                        TempData["MessageBody"] = "Please Fill Event Name.";
                        return(View("Create", EventModel));
                    }

                    if (string.IsNullOrEmpty(EventModel.EventDescription))
                    {
                        TempData["ShowMessage"] = "error";
                        TempData["MessageBody"] = "Please Fill  EventDescription.";
                        return(View("Create", EventModel));
                    }
                    //CultureInfo culture = new CultureInfo("en-US");
                    //DateTime TodayDate = Convert.ToDateTime(DateTime.Now.ToString("MM/dd/yyyy"), culture);
                    //if (Convert.ToDateTime(EventModel.EventDate.ToString("MM/dd/yyyy"), culture) < TodayDate)
                    //{

                    //    TempData["ShowMessage"] = "error";
                    //    TempData["MessageBody"] = "You cannot add old date event.";
                    //    return View("Create", EventModel);
                    //}

                    Mapper.CreateMap <CommunicationApp.Models.EventModel, CommunicationApp.Entity.Event>();
                    CommunicationApp.Entity.Event Event = Mapper.Map <CommunicationApp.Models.EventModel, CommunicationApp.Entity.Event>(EventModel);
                    string EventImage = "";
                    if (file != null)
                    {
                        if (Event.EventImage != "")
                        {   //Delete Old Image
                            string pathDel = Server.MapPath("~/EventPhoto");

                            FileInfo objfile = new FileInfo(pathDel);
                            if (objfile.Exists) //check file exsit or not
                            {
                                objfile.Delete();
                            }
                            //End :Delete Old Image
                        }

                        //Save the photo in Folder
                        var    fileExt  = Path.GetExtension(file.FileName);
                        string fileName = Guid.NewGuid() + fileExt;
                        var    subPath  = Server.MapPath("~/EventPhoto");

                        //Check SubPath Exist or Not
                        if (!Directory.Exists(subPath))
                        {
                            Directory.CreateDirectory(subPath);
                        }
                        //End : Check SubPath Exist or Not

                        var path = Path.Combine(subPath, fileName);
                        file.SaveAs(path);

                        EventImage = CommonCls.GetURL() + "/EventPhoto/" + fileName;
                    }

                    Event.CustomerId = Convert.ToInt32(Session["CustomerId"]);//CutomerId
                    Event.IsActive   = true;
                    Event.CreatedOn  = DateTime.Now;
                    Event.EventImage = EventImage;
                    _EventService.InsertEvent(Event);
                    List <int> CustomerIds = new List <int>();
                    var        Customers   = new List <Customer>();
                    try
                    {
                        if (EventModel.All == true)
                        {
                            EventModel.SelectedCustomer = null;
                            Customers = _CustomerService.GetCustomers().ToList();
                            foreach (var Customer in Customers)
                            {
                                CustomerIds.Add(Convert.ToInt32(Customer.CustomerId));
                                EventCustomer EventCustomer = new Entity.EventCustomer();
                                EventCustomer.EventId    = Event.EventId;
                                EventCustomer.CustomerId = Customer.CustomerId;
                                _EventCustomerService.InsertEventCustomer(EventCustomer);
                            }
                        }
                        else if (EventModel.SelectedCustomer != null)
                        {
                            foreach (var Customer in EventModel.SelectedCustomer)
                            {
                                CustomerIds.Add(Convert.ToInt32(Customer));
                                EventCustomer EventCustomer = new Entity.EventCustomer();
                                EventCustomer.EventId    = Event.EventId;
                                EventCustomer.CustomerId = Event.CustomerId;
                                _EventCustomerService.InsertEventCustomer(EventCustomer);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ErrorLogging.LogError(ex);
                        throw;
                    }



                    string Flag    = "12";//status for Event;
                    var    Message = "New event saved.";
                    //send notification
                    try
                    {
                        var CustomerList = _CustomerService.GetCustomers().Where(c => CustomerIds.Contains(c.CustomerId) && c.CustomerId != EventModel.CustomerId && c.IsActive == true).ToList();
                        foreach (var Customer in CustomerList)
                        {
                            if (Customer != null)
                            {
                                if (Customer.ApplicationId != null && Customer.ApplicationId != "")
                                {
                                    bool NotificationStatus = true;

                                    string JsonMessage = "{\"Flag\":\"" + Flag + "\",\"Message\":\"" + Message + "\"}";
                                    try
                                    {
                                        //Save Notification
                                        Notification Notification = new Notification();
                                        Notification.NotificationSendBy = 1;
                                        Notification.NotificationSendTo = Convert.ToInt32(Customer.CustomerId);
                                        Notification.IsRead             = false;
                                        Notification.Flag           = Convert.ToInt32(Flag);
                                        Notification.RequestMessage = Message;
                                        _Notification.InsertNotification(Notification);
                                        if (Customer.DeviceType == EnumValue.GetEnumDescription(EnumValue.DeviceType.Android))
                                        {
                                            CommonCls.SendGCM_Notifications(Customer.ApplicationId, JsonMessage, true);
                                        }
                                        else
                                        {
                                            int count = _Notification.GetNotifications().Where(c => c.NotificationSendTo == Convert.ToInt32(Customer.CustomerId) && c.IsRead == false).ToList().Count();
                                            //Dictionary<string, object> Dictionary = new Dictionary<string, object>();
                                            //Dictionary.Add("Flag", Flag);
                                            //Dictionary.Add("Message", Message);
                                            //NotificationStatus = PushNotificatinAlert.SendPushNotification(Customer.ApplicationId, Message, Flag, JsonMessage, Dictionary, 1, Convert.ToBoolean(Customer.IsNotificationSoundOn));
                                            CommonCls.TestSendFCM_Notifications(Customer.ApplicationId, JsonMessage, Message, count, true);
                                            ////Save Notification
                                            //Notification Notification = new Notification();
                                            //Notification.NotificationSendBy = 1;
                                            //Notification.NotificationSendTo = Customer.CustomerId;
                                            //Notification.IsRead = false;
                                            //Notification.RequestMessage = Message;
                                            //_Notification.InsertNotification(Notification);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        CommonCls.ErrorLog(ex.ToString());
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ErrorLogging.LogError(ex);
                        throw;
                    }

                    TempData["ShowMessage"] = "success";
                    TempData["MessageBody"] = "Event successfully saved.";
                    return(RedirectToAction("Index"));
                }
                var errors           = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray();
                var modelStateErrors = this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors);
                var CustomerList1    = _CustomerService.GetCustomers();
                EventModel.CustomersList = CustomerList1.Select(x => new SelectListItem {
                    Value = x.CustomerId.ToString(), Text = x.FirstName
                }).ToList();
                EventModel.CustomerId = 1;
                return(View(EventModel));
            }
            catch (Exception ex)
            {
                ErrorLogging.LogError(ex);

                return(View(EventModel));
            }
        }
        public ActionResult Edit([Bind(Include = "CustomerId,TrebId,WebsiteUrl,ApplicationID,Password,CompanyID,CompanyName,UserId,PhotoPath,AdminCompanyLogo,FirstName,LastName,MiddleName,EmailID,MobileNo,CountryID,StateID,CityID,ZipCode,Latitude,Longitude,CreatedOn,LastUpdatedOn,MobileVerifyCode,EmailVerifyCode,IsMobileVerified,IsEmailVerified,IsActive,AdminCompanyAddress")] AdminModel AdminModel, HttpPostedFileBase file, HttpPostedFileBase Logo)
        {
            UserPermissionAction("property", RoleAction.view.ToString());
            CheckPermission();
            TempData["ShowMessage"] = "";
            TempData["MessageBody"] = "";
            try
            {
                if (ModelState.IsValid)
                {
                    var CustomerFound = _CustomerService.GetCustomers().Where(c => ((c.EmailId.Trim() == AdminModel.EmailID.Trim() || c.MobileNo.Trim() == AdminModel.MobileNo.Trim()) && c.CustomerId != AdminModel.CustomerId)).FirstOrDefault();
                    if (CustomerFound == null)
                    {
                        var PhotoPath      = "";
                        var CompanyLogo    = "";
                        var CustomerUpdate = _CustomerService.GetCustomer(AdminModel.CustomerId);//.Where(c => c.CustomerId == AdminModel.CustomerId).FirstOrDefault();
                        if (CustomerUpdate != null)
                        {
                            var Company = _CompanyService.GetCompany(CustomerUpdate.CompanyID);
                            if (Company != null)
                            {
                                Company.CompanyName    = AdminModel.CompanyName != null ? AdminModel.CompanyName : "Company";
                                Company.CompanyAddress = AdminModel.AdminCompanyAddress;
                                if (Logo != null)
                                {
                                    CompanyLogo      = SaveFile(AdminModel.PhotoPath, Logo);
                                    Company.LogoPath = CompanyLogo;
                                }

                                _CompanyService.UpdateCompany(Company);
                            }

                            if (file != null)
                            {
                                PhotoPath = SaveFile(AdminModel.PhotoPath, file);
                                CustomerUpdate.PhotoPath = PhotoPath;
                            }

                            CustomerUpdate.FirstName  = AdminModel.FirstName;
                            CustomerUpdate.LastName   = AdminModel.LastName;
                            CustomerUpdate.MiddleName = AdminModel.MiddleName;
                            CustomerUpdate.Address    = AdminModel.Address;
                            CustomerUpdate.EmailId    = AdminModel.EmailID;
                            CustomerUpdate.DOB        = AdminModel.DOB;
                            CustomerUpdate.MobileNo   = AdminModel.MobileNo;
                            CustomerUpdate.WebsiteUrl = AdminModel.WebsiteUrl;
                            CustomerUpdate.IsActive   = true;
                            if (AdminModel.Designation != null && AdminModel.Designation != "")
                            {
                                CustomerUpdate.Designation = AdminModel.Designation;
                            }
                            _CustomerService.UpdateCustomer(CustomerUpdate);

                            //Update user table.
                            var User = _UserService.GetUser(CustomerUpdate.UserId);
                            User.FirstName = AdminModel.FirstName;
                            User.LastName  = AdminModel.LastName;
                            if (AdminModel != null)
                            {
                                User.Password = SecurityFunction.EncryptString(AdminModel.Password);
                                User.TrebId   = "0000000000000";
                            }
                            _UserService.UpdateUser(User);
                            TempData["ShowMessage"] = "success";
                            TempData["MessageBody"] = CustomerUpdate.FirstName + " is update successfully.";
                            return(RedirectToAction("Index", "Admin"));
                        }
                        else
                        {
                            TempData["ShowMessage"] = "error";
                            TempData["MessageBody"] = "Customer not found.";
                            return(RedirectToAction("Index", "Admin"));
                        }
                    }
                    else
                    {
                        TempData["ShowMessage"] = "error";

                        if (CustomerFound.EmailId.Trim() == AdminModel.EmailID.Trim())
                        {
                            TempData["MessageBody"] = AdminModel.EmailID + " is already exists.";
                        }
                        if (CustomerFound.TrebId.Trim() == AdminModel.TrebId.Trim())
                        {
                            TempData["MessageBody"] = AdminModel.TrebId + " is already exists.";
                        }
                        if (CustomerFound.MobileNo.Trim() == AdminModel.MobileNo.Trim())
                        {
                            TempData["MessageBody"] = "This" + " " + AdminModel.MobileNo + " is already exists.";
                        }
                        else
                        {
                            TempData["MessageBody"] = "Please fill the required field with valid data";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CommonCls.ErrorLog(ex.ToString());
                TempData["ShowMessage"] = "error";
                TempData["MessageBody"] = "Some unknown problem occured while proccessing save operation on " + AdminModel.FirstName + " client";
            }
            var errors           = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray();
            var modelStateErrors = this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors);

            ViewBag.UserId      = new SelectList(_UserService.GetUsers(), "UserId", "FirstName", AdminModel.UserId);
            ViewBag.CityID      = (AdminModel.CityID <= 0 ? "" : AdminModel.CityID.ToString());
            ViewBag.StateID     = (AdminModel.StateID <= 0 ? "" : AdminModel.StateID.ToString());
            ViewBag.Countrylist = new SelectList(_CountryService.GetCountries(), "CountryID", "CountryName", AdminModel.CountryID);
            ViewBag.Statelist   = new SelectList(_StateService.GetStates(), "StateID", "StateName", AdminModel.StateID);
            ViewBag.Citylist    = new SelectList(_CityService.GetCities(), "CityID", "CityName", AdminModel.CityID);


            return(View(AdminModel));
        }
        public ActionResult EditOfficeLocation([Bind(Include = "OfficeLocationId,OfficeAddress,City,TelePhoneNo,Fax,Email,Latitude,Longitude")] OfficeLocationModel officeLocationModel)
        {
            UserPermissionAction("customer", RoleAction.view.ToString());
            CheckPermission();
            TempData["ShowMessage"] = "";
            TempData["MessageBody"] = "";
            try
            {
                if (ModelState.IsValid)
                {
                    var OfficeLocationFound = _OfficeLocationService.GetOfficeLocations().Where(c => (c.OfficeAddress.Trim() == officeLocationModel.OfficeAddress.Trim()) && c.OfficeLocationId != officeLocationModel.OfficeLocationId).FirstOrDefault();
                    if (OfficeLocationFound == null)
                    {
                        var officeLocation = _OfficeLocationService.GetOfficeLocation(officeLocationModel.OfficeLocationId);
                        if (officeLocation != null)
                        {
                            officeLocation.OfficeAddress = officeLocationModel.OfficeAddress;
                            officeLocation.TelephoneNo   = officeLocationModel.TelephoneNo;
                            officeLocation.Fax           = officeLocationModel.Fax;
                            officeLocation.Email         = officeLocationModel.Email;
                            officeLocation.Latitude      = officeLocationModel.Latitude;
                            officeLocation.Longitude     = officeLocationModel.Longitude;
                            officeLocation.City          = officeLocationModel.City;
                            _OfficeLocationService.UpdateOfficeLocation(officeLocation);
                            TempData["ShowMessage"] = "success";
                            TempData["MessageBody"] = "Office Location successfully updated";
                            return(RedirectToAction("index"));
                        }
                    }
                    else
                    {
                        TempData["ShowMessage"] = "error";

                        if (OfficeLocationFound.Email.Trim() == officeLocationModel.Email.Trim())
                        {
                            TempData["MessageBody"] = officeLocationModel.Email + " is already exists.";
                        }
                        else if (OfficeLocationFound.Fax.Trim() == officeLocationModel.Fax.Trim())
                        {
                            TempData["MessageBody"] = officeLocationModel.Fax + " is already exists.";
                        }
                        else if (OfficeLocationFound.TelephoneNo.Trim() == officeLocationModel.TelephoneNo.Trim())
                        {
                            TempData["MessageBody"] = "This" + " " + officeLocationModel.TelephoneNo + " is already exists.";
                        }
                        else
                        {
                            TempData["MessageBody"] = "Please fill the required field with valid data";
                        }
                        return(View(officeLocationModel));
                    }
                }

                return(View(officeLocationModel));
            }
            catch (Exception ex)
            {
                CommonCls.ErrorLog(ex.ToString());
                TempData["ShowMessage"] = "error";
                TempData["MessageBody"] = ex.Message.ToString();
            }
            //var errors = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray();
            //var modelStateErrors = this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors);


            return(View());
        }
Beispiel #11
0
        public void SendNotificationsToUsers(int CustomerId, int ParentId, string Flag, int count)
        {
            string Message = "";
            //send notification
            // var Customers = _CustomerService.GetCustomers().Where(c => c.CustomerId != CustomerId && c.IsActive == true).ToList();
            CommonClass CommonClass = new Services.CommonClass();
            string      QStr        = "";
            DataTable   dt          = new DataTable();

            QStr = "Select * From Customer where CustomerId <> " + CustomerId + " and ParentId=" + ParentId + "  and IsActive=1";
            dt   = CommonClass.GetDataSet(QStr).Tables[0];
            try
            {
                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        string sql = "insert into [notification](RequestMessage,NotificationSendTo,NotificationSendBy,Flag,IsRead) values(@RequestMessage,@NotificationSendTo,@NotificationSendBy,@Flag,@IsRead)";
                        try
                        {
                            string constring = ConfigurationManager.ConnectionStrings["DataContext"].ConnectionString;
                            using (SqlConnection con = new SqlConnection(constring))
                            {
                                using (SqlCommand cmd = new SqlCommand(sql, con))
                                {
                                    cmd.CommandType = CommandType.Text;
                                    cmd.Parameters.AddWithValue("@RequestMessage", Message);
                                    cmd.Parameters.AddWithValue("@NotificationSendTo", dr["CustomerId"].ToString());
                                    cmd.Parameters.AddWithValue("@NotificationSendBy", CustomerId);
                                    cmd.Parameters.AddWithValue("@Flag", Flag);
                                    cmd.Parameters.AddWithValue("@IsRead", false);
                                    con.Open();
                                    int rowsAffected = cmd.ExecuteNonQuery();
                                    cmd.Dispose();
                                    con.Close();
                                    con.Dispose();
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        var ApplicationId = dr["ApplicationId"].ToString();
                        var DeviceType    = dr["DeviceType"].ToString();
                        var Trebid        = dr["Trebid"].ToString();
                        //var IsNotificationSoundOn = Convert.ToBoolean(dr["IsNotificationSoundOn"]);
                        if (ApplicationId != null && ApplicationId != "")
                        {
                            bool NotificationStatus = true;

                            string JsonMessage = "{\"Flag\":\"" + Flag + "\",\"Message\":\"" + Message + "\"}";

                            if (DeviceType == EnumValue.GetEnumDescription(EnumValue.DeviceType.Android))
                            {
                                CommonCls.SendGCM_Notifications(ApplicationId, JsonMessage, true);
                            }
                            else
                            {
                                string constring = ConfigurationManager.ConnectionStrings["DataContext"].ConnectionString;

                                using (SqlConnection con = new SqlConnection(constring))
                                {
                                    con.Open();
                                    using (SqlCommand thisCommand = new SqlCommand("SELECT COUNT(*) FROM Notification where NotificationSendTo=@NotificationSendTo and isread=0 ", con))
                                    {
                                        thisCommand.Parameters.AddWithValue("@NotificationSendTo", Convert.ToInt32(dr["CustomerId"].ToString()));
                                        count = (int)(thisCommand.ExecuteScalar());
                                    }

                                    con.Close();
                                    con.Dispose();
                                }
                                //Dictionary<string, object> Dictionary = new Dictionary<string, object>();
                                //Dictionary.Add("Flag", Flag);
                                //Dictionary.Add("Message", Message);
                                //NotificationStatus = PushNotificatinAlert.SendPushNotification(ApplicationId, Message, Flag.ToString(), JsonMessage, Dictionary, 1, Convert.ToBoolean(true));
                                CommonCls.TestSendFCM_Notifications(ApplicationId, JsonMessage, Message, count, true);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CommonCls.ErrorLog(ex.ToString());
            }
        }