Example #1
0
        public string Validate(VisaDTO visa)
        {
            if (null == visa)
            {
                return(GenericMessages.ObjectIsNull);
            }
            //if (null == visa.Agent)
            //return GenericMessages.ObjectIsNull;
            if (null == visa.Sponsor)
            {
                return(GenericMessages.ObjectIsNull);
            }
            if (null == visa.Condition)
            {
                return(GenericMessages.ObjectIsNull);
            }

            if (String.IsNullOrEmpty(visa.VisaNumber))
            {
                return(visa.VisaNumber + " " + GenericMessages.StringIsNullOrEmpty);
            }

            if (visa.VisaNumber.Length > 255)
            {
                return(visa.VisaNumber + " can not be more than 255 characters ");
            }

            return(string.Empty);
        }
Example #2
0
        public string Disable(VisaDTO visa)
        {
            if (visa == null)
            {
                return(GenericMessages.ObjectIsNull);
            }

            string stat;
            var    iDbContext = DbContextUtil.GetDbContextInstance();

            try
            {
                _visaRepository.Update(visa);
                _unitOfWork.Commit();
                stat = string.Empty;
            }
            catch (Exception exception)
            {
                stat = exception.Message;
            }
            finally
            {
                iDbContext.Dispose();
            }
            return(stat);
        }
Example #3
0
        public bool ObjectExists(VisaDTO visa)
        {
            var objectExists = false;
            var iDbContext   = DbContextUtil.GetDbContextInstance();

            try
            {
                var visaRepository = new Repository <VisaDTO>(iDbContext);
                var visaExists     = visaRepository.Query()
                                     .Filter(visaDTO => visaDTO.VisaNumber == visa.VisaNumber && visaDTO.Id != visa.Id)
                                     .Get()
                                     .FirstOrDefault();
                if (visaExists != null)
                {
                    objectExists = true;
                }
            }

            finally
            {
                iDbContext.Dispose();
            }

            return(objectExists);
        }
Example #4
0
        private void MapVisa(ref VisaDTO visa, VisaDTO visaDto)
        {
            visa.VisaNumber   = visaDto.VisaNumber;
            visa.VisaQuantity = visaDto.VisaQuantity;
            visa.VisaDate     = visaDto.VisaDate;

            visa.Sponsor.FullName       = visaDto.Sponsor.FullName.ToUpper();
            visa.Sponsor.PassportNumber = visaDto.Sponsor.PassportNumber;
            visa.Sponsor.Address.Mobile = visaDto.Sponsor.Address.Mobile;
            visa.Sponsor.Address.City   = visaDto.Sponsor.Address.City.ToUpper();

            if (visaDto.AgencyId != null && visaDto.AgencyId != -1)
            {
                visa.AgencyId                 = visaDto.AgencyId;
                visa.Sponsor.AgencyId         = visaDto.AgencyId;
                visa.Sponsor.Address.AgencyId = visaDto.AgencyId;//??null;
                visa.Condition.AgencyId       = visaDto.AgencyId;
                visa.ForeignAgentId           = WebUtility.GetAgentIdForTheAgency(visaDto.AgencyId);
            }
            else
            {
                visa.AgencyId                 = null;
                visa.Sponsor.AgencyId         = null;
                visa.Sponsor.Address.AgencyId = null;
                visa.Condition.AgencyId       = null;
            }

            visa.Condition.Salary        = visaDto.Condition.Salary;
            visa.Condition.Religion      = visaDto.Condition.Religion;
            visa.Condition.ContratPeriod = visaDto.Condition.ContratPeriod;
            visa.Condition.Profession    = visaDto.Condition.Profession;
            visa.Condition.Age           = visaDto.Condition.Age;
            visa.Condition.Complexion    = visaDto.Condition.Complexion;
        }
Example #5
0
        public string InsertOrUpdate(VisaDTO visa)
        {
            try
            {
                var validate = Validate(visa);
                if (!string.IsNullOrEmpty(validate))
                {
                    return(validate);
                }

                if (ObjectExists(visa))
                {
                    return(GenericMessages.DatabaseErrorRecordAlreadyExists);
                }

                visa.Synced                 = false;
                visa.Sponsor.Synced         = false;
                visa.Sponsor.Address.Synced = false;
                visa.Condition.Synced       = false;

                visa.Sponsor.DateLastModified         = DateTime.Now;
                visa.Sponsor.Address.DateLastModified = DateTime.Now;
                visa.Condition.DateLastModified       = DateTime.Now;

                _visaRepository.InsertUpdate(visa);
                _unitOfWork.Commit();
                return(string.Empty);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Example #6
0
        public bool DeleteVisaes(IUnitOfWork sourceUnitOfWork, IUnitOfWork destinationUnitOfWork)
        {
            List <VisaDTO> addressDtos = sourceUnitOfWork.Repository <VisaDTO>()
                                         .Query()
                                         .Get(-1)
                                         .ToList();

            foreach (VisaDTO source in addressDtos)
            {
                VisaDTO adr1        = source;
                var     destination =
                    destinationUnitOfWork.Repository <VisaDTO>()
                    .Query()
                    .Filter(i => i.RowGuid == adr1.RowGuid)
                    .Get(-1)//don't use .Get() to make sure both sides of data are disabled
                    .FirstOrDefault();

                if (destination != null)
                {
                    sourceUnitOfWork.Repository <VisaDTO>().Delete(source.Id);
                    destinationUnitOfWork.Repository <VisaDTO>().Delete(destination.Id);

                    sourceUnitOfWork.Commit();
                    destinationUnitOfWork.Commit();
                }
            }

            return(true);
        }
Example #7
0
        public ActionResult Detach(VisaDTO visa)
        {
            try
            {
                var employeeService = new EmployeeService(false, false);
                var criteria        = new SearchCriteria <EmployeeDTO>
                {
                    CurrentUserId = WebSecurity.CurrentUserId
                };
                criteria.FiList.Add(e => e.VisaId == visa.Id);
                var employees = employeeService.GetAll(criteria).ToList();

                foreach (var employeeDTO in employees)
                {
                    employeeDTO.VisaId = null;
                    employeeService.InsertOrUpdate(employeeDTO);
                }

                employeeService.Dispose();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Example #8
0
        public ActionResult Create(VisaDTO visaDto)
        {
            try
            {
                if (visaDto.Id == 0)
                {
                    var visaService = new VisaService(false, true);
                    var visa        = GetNewVisa();

                    MapVisa(ref visa, visaDto);

                    string stat = visaService.InsertOrUpdate(visa);
                    visaService.Dispose();

                    if (!string.IsNullOrEmpty(stat))
                    {
                        ModelState.AddModelError("", stat);
                        //return View();
                    }
                    else
                    {
                        return(RedirectToAction("Index"));
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                //
            }
            // If we got this far, something failed, redisplay form
            return(View());
        }
Example #9
0
        public ActionResult Delete(VisaDTO visaDto)
        {
            try
            {
                var visaService = new VisaService(false, true);
                var visa        = visaService.Find(visaDto.Id.ToString());

                if (visa != null)
                {
                    visaService.Delete(visa.Id.ToString());
                    visaService.Dispose();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Example #10
0
        public ActionResult Details(string visaId)
        {
            int visId   = EncryptionUtility.Hash64Decode(visaId);
            var visaDTO = new VisaDTO
            {
                Sponsor = new VisaSponsorDTO
                {
                    Address = new AddressDTO()
                },
                Condition = new VisaConditionDTO()
            };

            if (visId != 0)
            {
                visaDTO = new VisaService(true, true)
                          .GetAll()
                          .ToList()
                          .FirstOrDefault(v => v.Id == visId);
            }

            return(View(visaDTO));
        }
Example #11
0
        public ActionResult Edit(VisaDTO visaDto)
        {
            try
            {
                var visaService = new VisaService(false, true);
                var cri         = new SearchCriteria <VisaDTO>()
                {
                    CurrentUserId = WebSecurity.CurrentUserId
                };
                cri.FiList.Add(v => v.Id == visaDto.Id);
                var visa = visaService.GetAll(cri).ToList().FirstOrDefault();
                if (visa != null)
                {
                    MapVisa(ref visa, visaDto);

                    string stat = visaService.InsertOrUpdate(visa);
                    visaService.Dispose();

                    if (!string.IsNullOrEmpty(stat))
                    {
                        ModelState.AddModelError("", stat);
                        //return View();
                    }
                    else
                    {
                        return(RedirectToAction("Index"));
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                //
            }
            // If we got this far, something failed, redisplay form
            return(View());
        }
Example #12
0
        public bool SyncVisas(IUnitOfWork sourceUnitOfWork, IUnitOfWork destinationUnitOfWork)
        {
            Expression <Func <VisaDTO, bool> > filter =
                a => !a.Synced && a.DateLastModified > LastServerSyncDate;

            if (!ToServerSyncing)
            {
                Expression <Func <VisaDTO, bool> > filter2 =
                    a => a.Agency != null &&
                    a.Agency.RowGuid == Singleton.Agency.RowGuid;
                filter = filter.And(filter2);
            }

            var sourceList = sourceUnitOfWork.Repository <VisaDTO>().Query()
                             .Include(h => h.Agent, h => h.Sponsor, h => h.Condition, h => h.Agency)
                             .Filter(filter)
                             .Get(1)
                             .ToList();

            if (sourceList.Any())
            {
                _updatesFound = true;
                var destAgents =
                    destinationUnitOfWork.Repository <AgentDTO>().Query()
                    .Get(1)
                    .ToList();
                var destLocalAgencies =
                    destinationUnitOfWork.Repository <AgencyDTO>().Query()
                    .Filter(a => a.Id == Singleton.Agency.Id)
                    .Get(1)
                    .ToList();

                var destHeaders =
                    destinationUnitOfWork.Repository <VisaSponsorDTO>().Query()
                    .Filter(a => a.AgencyId == Singleton.Agency.Id)
                    .Get(1)
                    .ToList();

                var destFooters =
                    destinationUnitOfWork.Repository <VisaConditionDTO>().Query()
                    .Filter(a => a.AgencyId == Singleton.Agency.Id)
                    .Get(1)
                    .ToList();

                var destList =
                    destinationUnitOfWork.Repository <VisaDTO>().Query()
                    .Filter(a => a.AgencyId == Singleton.Agency.Id)
                    .Include(h => h.Agent, h => h.Sponsor, h => h.Condition, h => h.Agency)
                    .Get(1)
                    .ToList();

                foreach (var source in sourceList)
                {
                    var destination =
                        destList.FirstOrDefault(i => i.RowGuid == source.RowGuid);

                    //To Prevent ServerData Overriding
                    if (destination == null)
                    {
                        destination = new VisaDTO();
                    }
                    else if (ToServerSyncing && !destination.Synced)
                    {
                        continue;
                    }

                    try
                    {
                        Mapper.Reset();
                        Mapper.CreateMap <VisaDTO, VisaDTO>()
                        .ForMember("Agent", option => option.Ignore())
                        .ForMember("Agency", option => option.Ignore())
                        .ForMember("Sponsor", option => option.Ignore())
                        .ForMember("Condition", option => option.Ignore())
                        .ForMember("Id", option => option.Ignore())
                        .ForMember("Synced", option => option.Ignore());
                        destination = Mapper.Map(source, destination);

                        destination.CreatedByUserId = GetDestCreatedModifiedByUserId(source.CreatedByUserId,
                                                                                     sourceUnitOfWork, destinationUnitOfWork);
                        destination.ModifiedByUserId = GetDestCreatedModifiedByUserId(source.ModifiedByUserId,
                                                                                      sourceUnitOfWork, destinationUnitOfWork);
                        //destVisaDto.Id = destVisaId;
                    }
                    catch (Exception ex)
                    {
                        LogUtil.LogError(ErrorSeverity.Critical, "SyncVisas Mapping",
                                         ex.Message + Environment.NewLine + ex.InnerException, UserName, Agency);
                    }
                    try
                    {
                        #region Foreign Keys

                        var agentDTO =
                            destAgents.FirstOrDefault(c => source.Agent != null && c.RowGuid == source.Agent.RowGuid);
                        {
                            destination.Agent          = agentDTO;
                            destination.ForeignAgentId = agentDTO != null ? agentDTO.Id : 1;
                        }

                        var agencyDTO =
                            destLocalAgencies.FirstOrDefault(
                                c => source.Agency != null && c.RowGuid == source.Agency.RowGuid);
                        {
                            destination.Agency   = agencyDTO;
                            destination.AgencyId = agencyDTO != null ? agencyDTO.Id : (int?)null;
                        }

                        var headerDto =
                            destHeaders.FirstOrDefault(
                                c => source.Sponsor != null && c.RowGuid == source.Sponsor.RowGuid);
                        {
                            destination.Sponsor   = headerDto;
                            destination.SponsorId = headerDto != null ? headerDto.Id : 1;
                        }

                        var footerDto =
                            destFooters.FirstOrDefault(
                                c => source.Condition != null && c.RowGuid == source.Condition.RowGuid);
                        {
                            destination.Condition   = footerDto;
                            destination.ConditionId = footerDto != null ? footerDto.Id : 1;
                        }

                        #endregion

                        destination.Synced = true;
                        destinationUnitOfWork.Repository <VisaDTO>().InsertUpdate(destination);
                    }
                    catch (Exception ex)
                    {
                        _errorsFound = true;
                        LogUtil.LogError(ErrorSeverity.Critical, "SyncVisas Crud",
                                         ex.Message + Environment.NewLine + ex.InnerException, UserName, Agency);
                        return(false);
                    }
                }
                var changes = destinationUnitOfWork.Commit();
                if (changes < 0)
                {
                    _errorsFound = true;
                    LogUtil.LogError(ErrorSeverity.Critical, "SyncVisas Commit",
                                     "Problem Commiting SyncVisas Method", UserName, Agency);
                    return(false);
                }
            }
            return(true);
        }