Exemple #1
0
        public async Task <ActionResult> AddOrEditContactPerson(OtherContactPersonModel contact)
        {
            if (ModelState.IsValid)
            {
                if (contact.ConVoterIdFileName != null && contact.ConVoterIdFilePath != null)
                {
                    if (System.IO.File.Exists(Server.MapPath(_path + "VoterIds/" + contact.ConVoterIdFileName)))
                    {
                        System.IO.File.Delete(Server.MapPath(_path + "VoterIds/" + contact.ConVoterIdFileName));
                    }
                }

                if (contact.ConAdhaarFileName != null && contact.ConAdhaarNumberFilePath != null)
                {
                    if (System.IO.File.Exists(Server.MapPath(_path + "ADHRs/" + contact.ConAdhaarFileName)))
                    {
                        System.IO.File.Delete(Server.MapPath(_path + "ADHRs/" + contact.ConAdhaarFileName));
                    }
                }
                if (contact.ConPanFileName != null && contact.ConPanNumberFilePath != null)
                {
                    if (System.IO.File.Exists(Server.MapPath(_path + "PanCards/" + contact.ConPanFileName)))
                    {
                        System.IO.File.Delete(Server.MapPath(_path + "PanCards/" + contact.ConPanFileName));
                    }
                }
                if (contact.ConVoterIdFilePath != null)
                {
                    contact.ConVoterIdFileName = SaveImageFile(contact.ConVoterIdFilePath, "/VoterIds");
                }
                if (contact.ConPanNumberFilePath != null)
                {
                    contact.ConPanFileName = SaveImageFile(contact.ConPanNumberFilePath, "PanCards/");
                }
                if (contact.ConAdhaarNumberFilePath != null)
                {
                    contact.ConAdhaarFileName = SaveImageFile(contact.ConAdhaarNumberFilePath, "ADHRs/");
                }

                var pwd = CommonModel.RandomPassword(8);
                if (contact.IsUser)
                {
                    contact.Password = Encrypt_Decript_Code.encrypt_decrypt.Encrypt(pwd, true);
                }

                contact.UserTypeId = 1;
                contact.UserId     = CurrentUser.UserId;
                contact.CompanyId  = contact.RefKey;

                if (contact.ContactId == null)
                {
                    contact.EventAction = 'I';
                }
                else
                {
                    contact.EventAction = 'U';
                }
                CompanyModel comp     = new CompanyModel();
                var          response = await _ContactPersonRepo.AddUpdateContactDetails(contact);

                if (response.IsSuccess)
                {
                    contact.ContactId = new Guid(response.result);
                    if (contact.EventAction == 'U')
                    {
                        if (contact.IsUser && !contact.CurrentIsUser)
                        {
                            var Templates = await _templateRepo.GetTemplateByActionId(12, CurrentUser.CompanyId);

                            if (Templates.Count > 0)
                            {
                                CurrentUser.Email = contact.ConEmailAddress;
                                var WildCards = CommonModel.GetWildCards(null);
                                var U         = WildCards.Where(x => x.Text.ToUpper() == "NAME").FirstOrDefault();
                                U.Val = contact.ConFirstName;
                                U     = WildCards.Where(x => x.Text.ToUpper() == "PASSWORD").FirstOrDefault();
                                U.Val = pwd;
                                U     = WildCards.Where(x => x.Text.ToUpper() == "USER NAME").FirstOrDefault();
                                U.Val = contact.ConEmailAddress;
                                U     = WildCards.Where(x => x.Text.ToUpper() == "CUSTOMER SUPPORT NUMBER").FirstOrDefault();
                                U.Val = CurrentUser.CustomerCareNumber;
                                U     = WildCards.Where(x => x.Text.ToUpper() == "CUSTOMER SUPPORT EMAIL").FirstOrDefault();
                                U.Val = CurrentUser.ContactCareEmail;
                                CurrentUser.Mobile = contact.ConMobileNumber;
                                var c = WildCards.Where(x => x.Val != string.Empty).ToList();
                                await _emailSmsServices.Send(Templates, c, CurrentUser);
                            }
                        }
                    }
                    else
                    {
                        if (contact.IsUser)
                        {
                            var Templates = await _templateRepo.GetTemplateByActionId(12, CurrentUser.CompanyId);

                            if (Templates.Count > 0)
                            {
                                CurrentUser.Email = contact.ConEmailAddress;
                                var WildCards = CommonModel.GetWildCards(null);
                                var U         = WildCards.Where(x => x.Text.ToUpper() == "NAME").FirstOrDefault();
                                U.Val = contact.ConFirstName;
                                U     = WildCards.Where(x => x.Text.ToUpper() == "PASSWORD").FirstOrDefault();
                                U.Val = pwd;
                                U     = WildCards.Where(x => x.Text.ToUpper() == "USER NAME").FirstOrDefault();
                                U.Val = contact.ConEmailAddress;
                                CurrentUser.Mobile = contact.ConMobileNumber;
                                var c = WildCards.Where(x => x.Val != string.Empty).ToList();
                                await _emailSmsServices.Send(Templates, c, CurrentUser);
                            }
                        }
                    }
                }
                if (TempData["Comp"] != null)
                {
                    comp = TempData["Comp"] as CompanyModel;
                    var Location = _dropdown.BindLocationNew(contact.LocationId).FirstOrDefault();
                    contact.LocationName = Location.Text;
                    comp.Contacts.Add(contact);
                    comp.ActiveTab   = "tab-4";
                    comp.Action      = 'I';
                    TempData["Comp"] = comp;
                    comp.Contact     = new OtherContactPersonModel
                    {
                        AddressTypelist = new SelectList(await CommonModel.GetLookup("Address"), "value", "Text"),
                        RefKey          = comp.CompanyId,
                        CountryList     = new SelectList(_dropdown.BindCountry(), "Value", "Text"),
                        StateList       = new SelectList(Enumerable.Empty <SelectList>()),
                        // CityList = new SelectList(Enumerable.Empty<SelectList>())
                        LocationList = new SelectList(Enumerable.Empty <SelectListItem>())
                    };
                }
                else
                {
                    comp.Action = 'U';
                }
                TempData["response"] = response;
                if (comp.Action == 'I')
                {
                    return(View("Create", comp));
                }
                else
                {
                    comp = await GetCompany(contact.RefKey);

                    comp.ActiveTab = "tab-3";
                    return(View("Edit", comp));
                }
            }
            else
            {
                var comp = TempData["Comp"] as CompanyModel;
                if (comp != null)
                {
                    comp.Contact = contact;
                    comp.Contact.AddressTypelist = new SelectList(await CommonModel.GetLookup("Address"), "value", "Text");
                    comp.Contact.RefKey          = comp.CompanyId;
                    comp.Contact.CountryList     = new SelectList(_dropdown.BindCountry(), "Value", "Text");
                    comp.Contact.StateList       = new SelectList(Enumerable.Empty <SelectList>());
                    // CityList = new SelectList(Enumerable.Empty<SelectList>())
                    comp.Contact.LocationList = new SelectList(Enumerable.Empty <SelectListItem>());
                }
                comp.ActiveTab = "tab-3";

                if (comp.Action == 'I')
                {
                    return(View("Create", comp));
                }
                else
                {
                    comp = await GetCompany(contact.RefKey);

                    return(View("Edit", comp));
                }
            }
        }
        public async Task <ActionResult> AddOrPersonContactDetails(OtherContactPersonModel contact)
        {
            if (contact.ConAdhaarNumberFilePath != null && contact.ConAdhaarFileName != null)
            {
                if (System.IO.File.Exists(Server.MapPath(_path + "ADHRS/" + contact.ConAdhaarFileName)))
                {
                    System.IO.File.Delete(Server.MapPath(_path + "ADHRS/" + contact.ConAdhaarFileName));
                }
            }
            if (contact.ConVoterIdFileName != null && contact.ConVoterIdFilePath != null)
            {
                if (System.IO.File.Exists(Server.MapPath(_path + "VoterIds/" + contact.ConVoterIdFileName)))
                {
                    System.IO.File.Delete(Server.MapPath(_path + "VoterIds/" + contact.ConVoterIdFileName));
                }
            }
            if (contact.ConPanFileName != null && contact.ConPanNumberFilePath != null)
            {
                if (System.IO.File.Exists(Server.MapPath(_path + "PANCards/" + contact.ConPanFileName)))
                {
                    System.IO.File.Delete(Server.MapPath(_path + "PANCards/" + contact.ConPanFileName));
                }
            }
            if (contact.ConAdhaarNumberFilePath != null)
            {
                contact.ConAdhaarFileName = SaveImageFile(contact.ConAdhaarNumberFilePath, "ADHRS");
            }
            if (contact.ConVoterIdFilePath != null)
            {
                contact.ConVoterIdFileName = SaveImageFile(contact.ConVoterIdFilePath, "VoterIds");
            }
            if (contact.ConPanNumberFilePath != null)
            {
                contact.ConPanFileName = SaveImageFile(contact.ConPanNumberFilePath, "PANCards");
            }
            var pwd = CommonModel.RandomPassword(8);

            if (contact.IsUser)
            {
                contact.Password = Encrypt_Decript_Code.encrypt_decrypt.Encrypt(pwd, true);
            }
            if (contact.ContactId != null)
            {
                contact.EventAction = 'U';
            }
            else
            {
                contact.EventAction = 'I';
            }
            var Client = TempData["client"] as ClientModel;

            if (TempData["client"] != null)
            {
                contact.RefKey = Client.ClientId;
            }


            contact.UserId     = CurrentUser.UserId;
            contact.CompanyId  = CurrentUser.CompanyId;
            contact.UserTypeId = 2;
            var response = await _contactPerson.AddUpdateContactDetails(contact);

            if (response.IsSuccess)
            {
                if (contact.EventAction == 'U')
                {
                    if (contact.IsUser && !contact.CurrentIsUser)
                    {
                        var Templates = await _templateRepo.GetTemplateByActionId((int)EmailActions.USER_REGISTRATION, CurrentUser.CompanyId);

                        CurrentUser.Email = contact.ConEmailAddress;
                        var WildCards = CommonModel.GetWildCards(CurrentUser.CompanyId);
                        var U         = WildCards.Where(x => x.Text.ToUpper() == "NAME").FirstOrDefault();
                        U.Val = contact.ConFirstName;
                        U     = WildCards.Where(x => x.Text.ToUpper() == "PASSWORD").FirstOrDefault();
                        U.Val = pwd;
                        U     = WildCards.Where(x => x.Text.ToUpper() == "USER NAME").FirstOrDefault();
                        U.Val = contact.ConEmailAddress;
                        U     = WildCards.Where(x => x.Text.ToUpper() == "CUSTOMER SUPPORT NUMBER").FirstOrDefault();
                        U.Val = CurrentUser.CustomerCareNumber;
                        U     = WildCards.Where(x => x.Text.ToUpper() == "CUSTOMER SUPPORT EMAIL").FirstOrDefault();
                        U.Val = CurrentUser.ContactCareEmail;
                        CurrentUser.Mobile = contact.ConMobileNumber;
                        var c = WildCards.Where(x => x.Val != string.Empty).ToList();
                        if (Templates.Count > 0)
                        {
                            await _emailSmsServices.Send(Templates, c, CurrentUser);
                        }
                    }
                }
                else
                {
                    if (contact.IsUser)
                    {
                        var Templates = await _templateRepo.GetTemplateByActionId(12, CurrentUser.CompanyId);

                        CurrentUser.Email = contact.ConEmailAddress;
                        var WildCards = CommonModel.GetWildCards(CurrentUser.CompanyId);
                        var U         = WildCards.Where(x => x.Text.ToUpper() == "NAME").FirstOrDefault();
                        U.Val = contact.ConFirstName;
                        U     = WildCards.Where(x => x.Text.ToUpper() == "PASSWORD").FirstOrDefault();
                        U.Val = pwd;
                        U     = WildCards.Where(x => x.Text.ToUpper() == "USER NAME").FirstOrDefault();
                        U.Val = contact.ConEmailAddress;
                        U     = WildCards.Where(x => x.Text.ToUpper() == "CUSTOMER SUPPORT NUMBER").FirstOrDefault();
                        U.Val = CurrentUser.CustomerCareNumber;
                        U     = WildCards.Where(x => x.Text.ToUpper() == "CUSTOMER SUPPORT EMAIL").FirstOrDefault();
                        U.Val = CurrentUser.ContactCareEmail;
                        CurrentUser.Mobile = contact.ConMobileNumber;
                        var c = WildCards.Where(x => x.Val != string.Empty).ToList();
                        if (Templates != null)
                        {
                            await _emailSmsServices.Send(Templates, c, CurrentUser);
                        }
                    }
                }
            }
            TempData["response"] = response;
            if (TempData["client"] != null)
            {
                contact.ContactId = new Guid(response.result);
                var Location = dropdown.BindLocationNew(contact.LocationId).FirstOrDefault();
                contact.LocationName = Location.Text;
                Client.ContactPersons.Add(contact);
                Client.action      = 'I';
                Client.Activetab   = "tab-4";
                TempData["client"] = Client;
                return(View("Create", Client));
            }
            else
            {
                Client = await GetClient(contact.RefKey);

                Client.action    = 'U';
                Client.Activetab = "tab-3";
                return(View("Edit", Client));
            }
        }