Ejemplo n.º 1
0
        public string DisableRemark(ComplainRemarkDTO complainRemark)
        {
            if (complainRemark == null)
            {
                return(GenericMessages.ObjectIsNull);
            }

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

            try
            {
                _complainRemarkRepository.Update(complainRemark);
                _unitOfWork.Commit();
                stat = string.Empty;
            }
            catch (Exception exception)
            {
                stat = exception.Message;
            }
            finally
            {
                iDbContext.Dispose();
            }
            return(stat);
        }
Ejemplo n.º 2
0
        public ActionResult AddRemark(string compId)
        {
            int complainId        = EncryptionUtility.Hash64Decode(compId);
            var complainRemarkDTO = new ComplainRemarkDTO
            {
                AgencyId = Singleton.Agency.Id,
                Complain = new ComplainDTO()
            };

            if (complainId != 0)
            {
                var complainDTO = new ComplainService(true)
                                  .GetAll()
                                  .ToList()
                                  .FirstOrDefault(v => v.Id == complainId);

                if (complainDTO != null)
                {
                    complainRemarkDTO.Complain         = complainDTO;
                    complainRemarkDTO.ComplainId       = complainDTO.Id;
                    complainRemarkDTO.Complain.Remarks =
                        complainDTO.Remarks.OrderByDescending(c => c.RemarkDate).ToList();
                    complainRemarkDTO.RemarkDate = DateTime.Now;
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }
            return(View(complainRemarkDTO));
        }
Ejemplo n.º 3
0
        public string InsertOrUpdateRemark(ComplainRemarkDTO complainRemark)
        {
            try
            {
                var validate = ValidateRemark(complainRemark);
                if (!string.IsNullOrEmpty(validate))
                {
                    return(validate);
                }

                if (RemarkObjectExists(complainRemark))
                {
                    return(GenericMessages.DatabaseErrorRecordAlreadyExists);
                }

                complainRemark.Synced = false;
                _complainRemarkRepository.InsertUpdate(complainRemark);
                _unitOfWork.Commit();
                return(string.Empty);
            }
            catch (Exception exception)
            {
                return(exception.Message);
            }
        }
Ejemplo n.º 4
0
        public bool DeleteComplainRemarkes(IUnitOfWork sourceUnitOfWork, IUnitOfWork destinationUnitOfWork)
        {
            List <ComplainRemarkDTO> addressDtos = sourceUnitOfWork.Repository <ComplainRemarkDTO>()
                                                   .Query()
                                                   .Get(-1)
                                                   .ToList();

            foreach (ComplainRemarkDTO source in addressDtos)
            {
                ComplainRemarkDTO adr1 = source;
                var destination        =
                    destinationUnitOfWork.Repository <ComplainRemarkDTO>()
                    .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 <ComplainRemarkDTO>().Delete(source.Id);
                    destinationUnitOfWork.Repository <ComplainRemarkDTO>().Delete(destination.Id);

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

            return(true);
        }
Ejemplo n.º 5
0
        private void ExecuteAddNewComplainViewCommand()
        {
            SelectedComplain = new ComplainDTO
            {
                AgencyId     = Singleton.Agency.Id,
                ComplainDate = DateTime.Now,
                Priority     = ComplainProrityTypes.Medium,
                Type         = ComplainTypes.DidNotCall,
                Complain     = EnumUtil.GetEnumDesc(ComplainTypes.DidNotCall),
                Status       = ComplainStatusTypes.Opened
            };

            SelectedComplainRemark = new ComplainRemarkDTO
            {
                AgencyId = Singleton.Agency.Id,
                Complain = SelectedComplain
            };
        }
Ejemplo n.º 6
0
        public string ValidateRemark(ComplainRemarkDTO complainRemark)
        {
            if (null == complainRemark)
            {
                return(GenericMessages.ObjectIsNull);
            }

            if (String.IsNullOrEmpty(complainRemark.Remark))
            {
                return(complainRemark.Remark + " " + GenericMessages.StringIsNullOrEmpty);
            }

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

            return(string.Empty);
        }
Ejemplo n.º 7
0
        public bool RemarkObjectExists(ComplainRemarkDTO complainRemark)
        {
            //var objectExists = false;
            //var iDbContext = DbContextUtil.GetDbContextInstance();
            //try
            //{
            //    var catRepository = new Repository<ComplainRemarkDTO>(iDbContext);
            //    var catExists = catRepository.Query()
            //        .Filter(bp => bp.FirstName == complainRemark.FirstName && bp.Id != complainRemark.Id && bp.Type == complainRemark.Type)
            //        .Get()
            //        .FirstOrDefault();
            //    if (catExists != null)
            //        objectExists = true;
            //}
            //finally
            //{
            //    iDbContext.Dispose();
            //}

            //return objectExists;
            return(false);
        }
Ejemplo n.º 8
0
        private void ExcuteSaveRemarkViewCommand(object obj)
        {
            try
            {
                if (!SaveComplain())
                {
                    return;
                }

                SelectedComplainRemark.Complain = SelectedComplain;
                _complainService.InsertOrUpdateRemark(SelectedComplainRemark);

                GetLiveComplainRemarks();
                SelectedComplainRemark = new ComplainRemarkDTO
                {
                    RemarkDate = DateTime.Now
                };
            }
            catch
            {
                MessageBox.Show("Can't Save Remark");
            }
        }
Ejemplo n.º 9
0
        public ActionResult AddRemark(ComplainRemarkDTO complainRemarkDTO)
        {
            try
            {
                var complainService = new ComplainService(false);
                var compDTO         = complainService.Find(complainRemarkDTO.ComplainId.ToString());

                var complainRemarkDTO2 = new ComplainRemarkDTO
                {
                    Complain   = compDTO,
                    AgencyId   = Singleton.Agency.Id,
                    RemarkDate = complainRemarkDTO.RemarkDate,
                    Remark     = complainRemarkDTO.Remark
                };

                complainService.InsertOrUpdateRemark(complainRemarkDTO2);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 10
0
        public bool SyncComplainRemarks(IUnitOfWork sourceUnitOfWork,
                                        IUnitOfWork destinationUnitOfWork)
        {
            Expression <Func <ComplainRemarkDTO, bool> > filter =
                a => !a.Synced && a.DateLastModified > LastServerSyncDate;

            if (!ToServerSyncing)
            {
                Expression <Func <ComplainRemarkDTO, bool> > filter2 =
                    a => a.Agency != null &&
                    a.Agency.RowGuid == Singleton.Agency.RowGuid;
                filter = filter.And(filter2);
            }
            var sourceList = sourceUnitOfWork.Repository <ComplainRemarkDTO>().Query()
                             .Include(a => a.Complain, a => a.Agency)
                             .Filter(filter)
                             .Get(1)
                             .ToList();

            var destLocalAgencies =
                destinationUnitOfWork.Repository <AgencyDTO>().Query()
                .Filter(a => a.Id == Singleton.Agency.Id)
                .Get(1)
                .ToList();

            if (sourceList.Any())
            {
                _updatesFound = true;
                var destEmployees =
                    destinationUnitOfWork.Repository <ComplainDTO>().Query()
                    .Filter(a => a.AgencyId == Singleton.Agency.Id)
                    .Get(1)
                    .ToList();

                var destList =
                    destinationUnitOfWork.Repository <ComplainRemarkDTO>().Query()
                    .Filter(a => a.AgencyId == Singleton.Agency.Id)
                    .Include(a => a.Complain)
                    .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 ComplainRemarkDTO();
                    }
                    else if (ToServerSyncing && !destination.Synced)
                    {
                        continue;
                    }

                    try
                    {
                        Mapper.Reset();
                        Mapper.CreateMap <ComplainRemarkDTO, ComplainRemarkDTO>()
                        .ForMember("Agency", option => option.Ignore())
                        .ForMember("AgencyId", option => option.Ignore())
                        .ForMember("Id", option => option.Ignore())
                        .ForMember("Complain", 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);
                    }
                    catch (Exception ex)
                    {
                        LogUtil.LogError(ErrorSeverity.Critical, "SyncComplainRemarks Mapping",
                                         ex.Message + Environment.NewLine + ex.InnerException, UserName, Agency);
                    }
                    try
                    {
                        #region Foreign Keys

                        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 employeeDto =
                            destEmployees.FirstOrDefault(
                                c => source.Complain != null && c.RowGuid == source.Complain.RowGuid);
                        {
                            destination.Complain   = employeeDto;
                            destination.ComplainId = employeeDto != null ? employeeDto.Id : 1;
                        }

                        #endregion

                        destination.Synced = true;
                        destinationUnitOfWork.Repository <ComplainRemarkDTO>()
                        .InsertUpdate(destination);
                    }
                    catch
                    {
                        _errorsFound = true;
                        LogUtil.LogError(ErrorSeverity.Critical, "SyncComplainRemarks Crud",
                                         "Problem On SyncComplainRemarks Crud Method", UserName, Agency);
                        return(false);
                    }
                }
                var changes = destinationUnitOfWork.Commit();
                if (changes < 0)
                {
                    _errorsFound = true;
                    LogUtil.LogError(ErrorSeverity.Critical, "SyncComplainRemarks Commit",
                                     "Problem Commiting SyncComplainRemarks Method", UserName, Agency);
                    return(false);
                }
            }
            return(true);
        }