public void AddBranchStorage(ServiceRequestModel <DocumentStorageViewModel> serviceRequestModel) { var branchRepo = _genericUnitOfWork.GetRepository <Branch, Guid>().GetAll(); var documentstoragelocationRepo = _genericUnitOfWork.GetRepository <DocumentStorageLocation, Guid>().GetAll(); var mapped = _mapper.Map <DocumentStorageViewModel, DocumentStorage>(serviceRequestModel.Model); mapped.Id = Guid.NewGuid(); if (serviceRequestModel.CurrentUserId != null) { mapped.CreatedById = serviceRequestModel.CurrentUserId.Value; } mapped.CreatedDate = GeneralService.CurrentDate; mapped.BranchId = serviceRequestModel.LoginInfo.LoginUserBranches.Select(x => x.Id).FirstOrDefault(); string branchShortName = branchRepo.Where(x => x.Id == mapped.BranchId).Select(x => x.ShortName).FirstOrDefault(); string categoryShortName = _genericUnitOfWork.GetRepository <Category, int>().GetAll().Where(x => x.Id == mapped.CategoryId.Value).Select(x => x.ShortName).FirstOrDefault(); mapped.BoxNumber = _sharedService.GetBranchStorageBoxNumber(RunningNumberType.BranchStorageBoxNo, GeneralService.CurrentDate.Year, branchShortName, categoryShortName); int scheduledYear = Convert.ToInt16(_genericUnitOfWork.GetRepository <Setting, string>().GetById("ShceduledDestructionDate").Value); mapped.ScheduledDestructionDate = GeneralService.CurrentDate.AddYears(scheduledYear); var storageLocation = documentstoragelocationRepo.SingleOrDefault(x => x.BranchId == mapped.BranchId); if (storageLocation == null) { throw new ArgumentNullException("Set branch storage location for this branch.", innerException: null); } mapped.LocationType = storageLocation.LocationType; mapped.RegionalStoreId = storageLocation.RegionalStoreId; mapped.RegionalBranchId = storageLocation.RegionalBranchId; _genericUnitOfWork.GetRepository <DocumentStorage, Guid>().Add(mapped); _genericUnitOfWork.SaveChanges(); }