Пример #1
0
        public IActionResult Post(Person person)
        {
            var validationResult = new PersonRegistrationService(PersonRepository).Register(person);

            if (validationResult.Any())
            {
                return(StatusCode((int)HttpStatusCode.UnprocessableEntity, validationResult));
            }

            return(Ok(CreatedAtAction(nameof(Person), new { id = person.Id }, person)));
        }
Пример #2
0
        private static async Task <PersonRegistrationService> InitCosmosAsync(IConfigurationSection configurationSection)
        {
            string           databaseName  = configurationSection.GetSection("DatabaseName").Value;
            string           containerName = configurationSection.GetSection("ContainerName").Value;
            string           account       = configurationSection.GetSection("Account").Value;
            string           key           = configurationSection.GetSection("Key").Value;
            CosmosClient     client        = new CosmosClient(account, key);
            DatabaseResponse database      = await client.CreateDatabaseIfNotExistsAsync(databaseName);

            var container = await client.GetDatabase(databaseName).CreateContainerIfNotExistsAsync(nameof(PersonRegistration), "/id");

            PersonRegistrationService cosmosService = new PersonRegistrationService(client, databaseName, containerName);

            return(cosmosService);
        }
Пример #3
0
        public ActionResult DeleteConfirmed(ReasonViewModel vm)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            if (ModelState.IsValid)
            {
                Person         person         = new PersonService(_unitOfWork).Find(vm.id);
                BusinessEntity businessentiry = _BusinessEntityService.Find(vm.id);
                JobWorker      jobworker      = _JobWorkerService.Find(vm.id);

                LogList.Add(new LogTypeViewModel
                {
                    ExObj = person,
                });

                LogList.Add(new LogTypeViewModel
                {
                    ExObj = businessentiry,
                });

                LogList.Add(new LogTypeViewModel
                {
                    ExObj = jobworker,
                });

                //Then find Ledger Account associated with the above Person.
                LedgerAccount ledgeraccount = _AccountService.GetLedgerAccountFromPersonId(vm.id);
                _AccountService.Delete(ledgeraccount.LedgerAccountId);

                //Then find all the Person Address associated with the above Person.
                PersonAddress personaddress = _PersonAddressService.GetShipAddressByPersonId(vm.id);
                _PersonAddressService.Delete(personaddress.PersonAddressID);


                IEnumerable <PersonContact> personcontact = new PersonContactService(_unitOfWork).GetPersonContactIdListByPersonId(vm.id);
                //Mark ObjectState.Delete to all the Person Contact For Above Person.
                foreach (PersonContact item in personcontact)
                {
                    new PersonContactService(_unitOfWork).Delete(item.PersonContactID);
                }

                IEnumerable <PersonBankAccount> personbankaccount = new PersonBankAccountService(_unitOfWork).GetPersonBankAccountIdListByPersonId(vm.id);
                //Mark ObjectState.Delete to all the Person Contact For Above Person.
                foreach (PersonBankAccount item in personbankaccount)
                {
                    new PersonBankAccountService(_unitOfWork).Delete(item.PersonBankAccountID);
                }

                IEnumerable <PersonProcess> personProcess = new PersonProcessService(_unitOfWork).GetPersonProcessIdListByPersonId(vm.id);
                //Mark ObjectState.Delete to all the Person Process For Above Person.
                foreach (PersonProcess item in personProcess)
                {
                    new PersonProcessService(_unitOfWork).Delete(item.PersonProcessId);
                }

                IEnumerable <PersonRegistration> personregistration = new PersonRegistrationService(_unitOfWork).GetPersonRegistrationIdListByPersonId(vm.id);
                //Mark ObjectState.Delete to all the Person Registration For Above Person.
                foreach (PersonRegistration item in personregistration)
                {
                    new PersonRegistrationService(_unitOfWork).Delete(item.PersonRegistrationID);
                }


                // Now delete the Parent JobWorker
                _JobWorkerService.Delete(jobworker);
                _BusinessEntityService.Delete(businessentiry);
                new PersonService(_unitOfWork).Delete(person);



                XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);

                try
                {
                    _unitOfWork.Save();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    ModelState.AddModelError("", message);
                    return(PartialView("_Reason", vm));
                }


                LogActivity.LogActivityDetail(new ActiivtyLogViewModel
                {
                    DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocCategoryConstants.JobWorker).DocumentTypeId,
                    DocId           = vm.id,
                    ActivityType    = (int)ActivityTypeContants.Deleted,
                    UserRemark      = vm.Reason,
                    User            = User.Identity.Name,
                    DocNo           = person.Name,
                    xEModifications = Modifications
                });

                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
Пример #4
0
        public ActionResult DeleteConfirmed(ReasonViewModel vm)
        {
            if (ModelState.IsValid)
            {
                Person         person         = new PersonService(_unitOfWork).Find(vm.id);
                BusinessEntity businessentiry = _BusinessEntityService.Find(vm.id);
                Courier        Courier        = _CourierService.Find(vm.id);

                ActivityLog al = new ActivityLog()
                {
                    ActivityType = (int)ActivityTypeContants.Deleted,
                    CreatedBy    = User.Identity.Name,
                    CreatedDate  = DateTime.Now,
                    DocId        = vm.id,
                    UserRemark   = vm.Reason,
                    Narration    = "Courier is deleted with Name:" + person.Name,
                    DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(TransactionDocCategoryConstants.SaleOrder).DocumentTypeId,
                    UploadDate   = DateTime.Now,
                };
                new ActivityLogService(_unitOfWork).Create(al);

                //Then find all the Person Address associated with the above Person.
                PersonAddress personaddress = _PersonAddressService.GetShipAddressByPersonId(vm.id);
                _PersonAddressService.Delete(personaddress.PersonAddressID);


                IEnumerable <PersonContact> personcontact = new PersonContactService(_unitOfWork).GetPersonContactIdListByPersonId(vm.id);
                //Mark ObjectState.Delete to all the Person Contact For Above Person.
                foreach (PersonContact item in personcontact)
                {
                    new PersonContactService(_unitOfWork).Delete(item.PersonContactID);
                }

                IEnumerable <PersonBankAccount> personbankaccount = new PersonBankAccountService(_unitOfWork).GetPersonBankAccountIdListByPersonId(vm.id);
                //Mark ObjectState.Delete to all the Person Contact For Above Person.
                foreach (PersonBankAccount item in personbankaccount)
                {
                    new PersonBankAccountService(_unitOfWork).Delete(item.PersonBankAccountID);
                }

                LedgerAccount LedgerAccount = new LedgerAccountService(_unitOfWork).GetLedgerAccountByPersondId(vm.id);
                new LedgerAccountService(_unitOfWork).Delete(LedgerAccount);


                IEnumerable <PersonRegistration> personregistration = new PersonRegistrationService(_unitOfWork).GetPersonRegistrationIdListByPersonId(vm.id);
                //Mark ObjectState.Delete to all the Person Registration For Above Person.
                foreach (PersonRegistration item in personregistration)
                {
                    new PersonRegistrationService(_unitOfWork).Delete(item.PersonRegistrationID);
                }


                // Now delete the Parent Courier
                _CourierService.Delete(Courier);
                _BusinessEntityService.Delete(businessentiry);
                new PersonService(_unitOfWork).Delete(person);


                try
                {
                    _unitOfWork.Save();
                }

                catch (Exception ex)
                {
                    string message = _exception.HandleException(ex);
                    ModelState.AddModelError("", message);
                    return(PartialView("_Reason", vm));
                }
                return(Json(new { success = true }));
            }
            return(PartialView("_Reason", vm));
        }
        //[ValidateAntiForgeryToken]
        public ActionResult _CreatePost(PersonViewModel PersonVm)
        {
            if (ModelState.IsValid)
            {
                if (PersonVm.PersonID == 0)
                {
                    Person         person         = Mapper.Map <PersonViewModel, Person>(PersonVm);
                    BusinessEntity businessentity = Mapper.Map <PersonViewModel, BusinessEntity>(PersonVm);
                    PersonAddress  personaddress  = Mapper.Map <PersonViewModel, PersonAddress>(PersonVm);
                    LedgerAccount  account        = Mapper.Map <PersonViewModel, LedgerAccount>(PersonVm);

                    person.IsActive     = true;
                    person.CreatedDate  = DateTime.Now;
                    person.ModifiedDate = DateTime.Now;
                    person.CreatedBy    = User.Identity.Name;
                    person.ModifiedBy   = User.Identity.Name;
                    person.ObjectState  = Model.ObjectState.Added;
                    new PersonService(_unitOfWork).Create(person);


                    int CurrentDivisionId = (int)System.Web.HttpContext.Current.Session["DivisionId"];
                    int CurrentSiteId     = (int)System.Web.HttpContext.Current.Session["SiteId"];

                    string Divisions = PersonVm.DivisionIds;
                    if (Divisions != null)
                    {
                        Divisions = "|" + Divisions.Replace(",", "|,|") + "|";
                    }
                    else
                    {
                        Divisions = "|" + CurrentDivisionId.ToString() + "|";
                    }

                    businessentity.DivisionIds = Divisions;

                    string Sites = PersonVm.SiteIds;
                    if (Sites != null)
                    {
                        Sites = "|" + Sites.Replace(",", "|,|") + "|";
                    }
                    else
                    {
                        Sites = "|" + CurrentSiteId.ToString() + "|";
                    }

                    businessentity.SiteIds = Sites;


                    new  BusinessEntityService(_unitOfWork).Create(businessentity);

                    personaddress.AddressType  = null;
                    personaddress.CreatedDate  = DateTime.Now;
                    personaddress.ModifiedDate = DateTime.Now;
                    personaddress.CreatedBy    = User.Identity.Name;
                    personaddress.ModifiedBy   = User.Identity.Name;
                    personaddress.ObjectState  = Model.ObjectState.Added;
                    new PersonAddressService(_unitOfWork).Create(personaddress);


                    account.LedgerAccountId      = db.LedgerAccount.Max(i => i.LedgerAccountId) + 1;
                    account.LedgerAccountName    = person.Name;
                    account.LedgerAccountSuffix  = person.Suffix;
                    account.LedgerAccountGroupId = PersonVm.LedgerAccountGroupId;
                    account.IsActive             = true;
                    account.CreatedDate          = DateTime.Now;
                    account.ModifiedDate         = DateTime.Now;
                    account.CreatedBy            = User.Identity.Name;
                    account.ModifiedBy           = User.Identity.Name;
                    account.ObjectState          = Model.ObjectState.Added;
                    new LedgerAccountService(_unitOfWork).Create(account);


                    if (PersonVm.CstNo != "" && PersonVm.CstNo != null)
                    {
                        PersonRegistration personregistration = new PersonRegistration();
                        personregistration.RegistrationType = PersonRegistrationType.CstNo;
                        personregistration.RegistrationNo   = PersonVm.CstNo;
                        personregistration.CreatedDate      = DateTime.Now;
                        personregistration.ModifiedDate     = DateTime.Now;
                        personregistration.CreatedBy        = User.Identity.Name;
                        personregistration.ModifiedBy       = User.Identity.Name;
                        personregistration.ObjectState      = Model.ObjectState.Added;
                        new PersonRegistrationService(_unitOfWork).Create(personregistration);
                    }

                    if (PersonVm.TinNo != "" && PersonVm.TinNo != null)
                    {
                        PersonRegistration personregistration = new PersonRegistration();
                        personregistration.RegistrationType = PersonRegistrationType.TinNo;
                        personregistration.RegistrationNo   = PersonVm.TinNo;
                        personregistration.CreatedDate      = DateTime.Now;
                        personregistration.ModifiedDate     = DateTime.Now;
                        personregistration.CreatedBy        = User.Identity.Name;
                        personregistration.ModifiedBy       = User.Identity.Name;
                        personregistration.ObjectState      = Model.ObjectState.Added;
                        new PersonRegistrationService(_unitOfWork).Create(personregistration);
                    }

                    if (PersonVm.PanNo != "" && PersonVm.PanNo != null)
                    {
                        PersonRegistration personregistration = new PersonRegistration();
                        personregistration.RegistrationType = PersonRegistrationType.PANNo;
                        personregistration.RegistrationNo   = PersonVm.PanNo;
                        personregistration.CreatedDate      = DateTime.Now;
                        personregistration.ModifiedDate     = DateTime.Now;
                        personregistration.CreatedBy        = User.Identity.Name;
                        personregistration.ModifiedBy       = User.Identity.Name;
                        personregistration.ObjectState      = Model.ObjectState.Added;
                        new PersonRegistrationService(_unitOfWork).Create(personregistration);
                    }


                    if (PersonVm.GstNo != "" && PersonVm.GstNo != null)
                    {
                        PersonRegistration personregistration = new PersonRegistration();
                        personregistration.RegistrationType = PersonRegistrationType.GstNo;
                        personregistration.RegistrationNo   = PersonVm.GstNo;
                        personregistration.CreatedDate      = DateTime.Now;
                        personregistration.ModifiedDate     = DateTime.Now;
                        personregistration.CreatedBy        = User.Identity.Name;
                        personregistration.ModifiedBy       = User.Identity.Name;
                        personregistration.ObjectState      = Model.ObjectState.Added;
                        new PersonRegistrationService(_unitOfWork).Create(personregistration);
                    }


                    if (PersonVm.AadharNo != "" && PersonVm.AadharNo != null)
                    {
                        PersonRegistration personregistration = new PersonRegistration();
                        personregistration.RegistrationType = PersonRegistrationType.AadharNo;
                        personregistration.RegistrationNo   = PersonVm.AadharNo;
                        personregistration.CreatedDate      = DateTime.Now;
                        personregistration.ModifiedDate     = DateTime.Now;
                        personregistration.CreatedBy        = User.Identity.Name;
                        personregistration.ModifiedBy       = User.Identity.Name;
                        personregistration.ObjectState      = Model.ObjectState.Added;
                        new PersonRegistrationService(_unitOfWork).Create(personregistration);
                    }


                    PersonRole personrole = new PersonRole();
                    personrole.PersonRoleId  = -1;
                    personrole.PersonId      = person.PersonID;
                    personrole.RoleDocTypeId = person.DocTypeId;
                    personrole.CreatedDate   = DateTime.Now;
                    personrole.ModifiedDate  = DateTime.Now;
                    personrole.CreatedBy     = User.Identity.Name;
                    personrole.ModifiedBy    = User.Identity.Name;
                    personrole.ObjectState   = Model.ObjectState.Added;
                    new PersonRoleService(_unitOfWork).Create(personrole);

                    int ProspectDocTypeId = new DocumentTypeService(_unitOfWork).Find(MasterDocTypeConstants.Prospect).DocumentTypeId;
                    if (person.DocTypeId == ProspectDocTypeId)
                    {
                        int CustomerDocTypeId = new DocumentTypeService(_unitOfWork).Find(MasterDocTypeConstants.Customer).DocumentTypeId;

                        PersonRole personrole1 = new PersonRole();
                        personrole.PersonRoleId   = -2;
                        personrole1.PersonId      = person.PersonID;
                        personrole1.RoleDocTypeId = CustomerDocTypeId;
                        personrole1.CreatedDate   = DateTime.Now;
                        personrole1.ModifiedDate  = DateTime.Now;
                        personrole1.CreatedBy     = User.Identity.Name;
                        personrole1.ModifiedBy    = User.Identity.Name;
                        personrole1.ObjectState   = Model.ObjectState.Added;
                        new PersonRoleService(_unitOfWork).Create(personrole1);
                    }


                    int ProcessId = new ProcessService(_unitOfWork).Find(ProcessConstants.Sales).ProcessId;

                    PersonProcess personprocess = new PersonProcess();
                    personprocess.PersonId     = person.PersonID;
                    personprocess.ProcessId    = ProcessId;
                    personprocess.CreatedDate  = DateTime.Now;
                    personprocess.ModifiedDate = DateTime.Now;
                    personprocess.CreatedBy    = User.Identity.Name;
                    personprocess.ModifiedBy   = User.Identity.Name;
                    personprocess.ObjectState  = Model.ObjectState.Added;
                    new PersonProcessService(_unitOfWork).Create(personprocess);


                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(View(PersonVm));
                    }

                    return(Json(new { success = true, PersonId = person.PersonID, Name = person.Name + ", " + person.Suffix + " [" + person.Code + "]" }));
                }
                else
                {
                    //string tempredirect = (Request["Redirect"].ToString());
                    Person             person         = Mapper.Map <PersonViewModel, Person>(PersonVm);
                    BusinessEntity     businessentity = Mapper.Map <PersonViewModel, BusinessEntity>(PersonVm);
                    PersonAddress      personaddress  = new PersonAddressService(_unitOfWork).Find(PersonVm.PersonAddressID);
                    LedgerAccount      account        = new LedgerAccountService(_unitOfWork).Find(PersonVm.AccountId);
                    PersonRegistration PersonCst      = new PersonRegistrationService(_unitOfWork).Find(PersonVm.PersonRegistrationCstNoID ?? 0);
                    PersonRegistration PersonTin      = new PersonRegistrationService(_unitOfWork).Find(PersonVm.PersonRegistrationTinNoID ?? 0);
                    PersonRegistration PersonPAN      = new PersonRegistrationService(_unitOfWork).Find(PersonVm.PersonRegistrationPanNoID ?? 0);
                    PersonRegistration PersonGst      = new PersonRegistrationService(_unitOfWork).Find(PersonVm.PersonRegistrationGstNoID ?? 0);
                    PersonRegistration PersonAadhar   = new PersonRegistrationService(_unitOfWork).Find(PersonVm.PersonRegistrationAadharNoID ?? 0);



                    person.IsActive     = true;
                    person.ModifiedDate = DateTime.Now;
                    person.ModifiedBy   = User.Identity.Name;
                    new PersonService(_unitOfWork).Update(person);


                    new BusinessEntityService(_unitOfWork).Update(businessentity);

                    personaddress.Address      = PersonVm.Address;
                    personaddress.CityId       = PersonVm.CityId;
                    personaddress.Zipcode      = PersonVm.Zipcode;
                    personaddress.ModifiedDate = DateTime.Now;
                    personaddress.ModifiedBy   = User.Identity.Name;
                    personaddress.ObjectState  = Model.ObjectState.Modified;
                    new PersonAddressService(_unitOfWork).Update(personaddress);


                    account.LedgerAccountName   = person.Name;
                    account.LedgerAccountSuffix = person.Suffix;
                    account.ModifiedDate        = DateTime.Now;
                    account.ModifiedBy          = User.Identity.Name;
                    new LedgerAccountService(_unitOfWork).Update(account);

                    if (PersonVm.CstNo != null && PersonVm.CstNo != "")
                    {
                        if (PersonCst != null)
                        {
                            PersonCst.RegistrationNo = PersonVm.CstNo;
                            new PersonRegistrationService(_unitOfWork).Update(PersonCst);
                        }
                        else
                        {
                            PersonRegistration personregistration = new PersonRegistration();
                            personregistration.PersonId         = PersonVm.PersonID;
                            personregistration.RegistrationType = PersonRegistrationType.CstNo;
                            personregistration.RegistrationNo   = PersonVm.CstNo;
                            personregistration.CreatedDate      = DateTime.Now;
                            personregistration.ModifiedDate     = DateTime.Now;
                            personregistration.CreatedBy        = User.Identity.Name;
                            personregistration.ModifiedBy       = User.Identity.Name;
                            personregistration.ObjectState      = Model.ObjectState.Added;
                            new PersonRegistrationService(_unitOfWork).Create(personregistration);
                        }
                    }

                    if (PersonVm.TinNo != null && PersonVm.TinNo != "")
                    {
                        if (PersonTin != null)
                        {
                            PersonTin.RegistrationNo = PersonVm.TinNo;
                            new PersonRegistrationService(_unitOfWork).Update(PersonTin);
                        }
                        else
                        {
                            PersonRegistration personregistration = new PersonRegistration();
                            personregistration.PersonId         = PersonVm.PersonID;
                            personregistration.RegistrationType = PersonRegistrationType.TinNo;
                            personregistration.RegistrationNo   = PersonVm.TinNo;
                            personregistration.CreatedDate      = DateTime.Now;
                            personregistration.ModifiedDate     = DateTime.Now;
                            personregistration.CreatedBy        = User.Identity.Name;
                            personregistration.ModifiedBy       = User.Identity.Name;
                            personregistration.ObjectState      = Model.ObjectState.Added;
                            new PersonRegistrationService(_unitOfWork).Create(personregistration);
                        }
                    }

                    if (PersonVm.PanNo != null && PersonVm.PanNo != "")
                    {
                        if (PersonPAN != null)
                        {
                            PersonPAN.RegistrationNo = PersonVm.PanNo;
                            new PersonRegistrationService(_unitOfWork).Update(PersonPAN);
                        }
                        else
                        {
                            PersonRegistration personregistration = new PersonRegistration();
                            personregistration.PersonId         = PersonVm.PersonID;
                            personregistration.RegistrationType = PersonRegistrationType.PANNo;
                            personregistration.RegistrationNo   = PersonVm.PanNo;
                            personregistration.CreatedDate      = DateTime.Now;
                            personregistration.ModifiedDate     = DateTime.Now;
                            personregistration.CreatedBy        = User.Identity.Name;
                            personregistration.ModifiedBy       = User.Identity.Name;
                            personregistration.ObjectState      = Model.ObjectState.Added;
                            new PersonRegistrationService(_unitOfWork).Create(personregistration);
                        }
                    }

                    if (PersonVm.GstNo != null && PersonVm.GstNo != "")
                    {
                        if (PersonGst != null)
                        {
                            PersonGst.RegistrationNo = PersonVm.GstNo;
                            new PersonRegistrationService(_unitOfWork).Update(PersonGst);
                        }
                        else
                        {
                            PersonRegistration personregistration = new PersonRegistration();
                            personregistration.PersonId         = PersonVm.PersonID;
                            personregistration.RegistrationType = PersonRegistrationType.GstNo;
                            personregistration.RegistrationNo   = PersonVm.GstNo;
                            personregistration.CreatedDate      = DateTime.Now;
                            personregistration.ModifiedDate     = DateTime.Now;
                            personregistration.CreatedBy        = User.Identity.Name;
                            personregistration.ModifiedBy       = User.Identity.Name;
                            personregistration.ObjectState      = Model.ObjectState.Added;
                            new PersonRegistrationService(_unitOfWork).Create(personregistration);
                        }
                    }

                    if (PersonVm.AadharNo != null && PersonVm.AadharNo != "")
                    {
                        if (PersonAadhar != null)
                        {
                            PersonAadhar.RegistrationNo = PersonVm.AadharNo;
                            new PersonRegistrationService(_unitOfWork).Update(PersonAadhar);
                        }
                        else
                        {
                            PersonRegistration personregistration = new PersonRegistration();
                            personregistration.PersonId         = PersonVm.PersonID;
                            personregistration.RegistrationType = PersonRegistrationType.AadharNo;
                            personregistration.RegistrationNo   = PersonVm.AadharNo;
                            personregistration.CreatedDate      = DateTime.Now;
                            personregistration.ModifiedDate     = DateTime.Now;
                            personregistration.CreatedBy        = User.Identity.Name;
                            personregistration.ModifiedBy       = User.Identity.Name;
                            personregistration.ObjectState      = Model.ObjectState.Added;
                            new PersonRegistrationService(_unitOfWork).Create(personregistration);
                        }
                    }


                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(View("Create", PersonVm));
                    }

                    return(Json(new { success = true, PersonId = person.PersonID, Name = person.Name + ", " + person.Suffix + " [" + person.Code + "]" }));
                }
            }
            return(View(PersonVm));
        }