Exemplo n.º 1
0
        public bool ObjectExists(AgencyDTO agency)
        {
            var objectExists = false;
            var iDbContext   = DbContextUtil.GetDbContextInstance();

            try
            {
                var catRepository = new Repository <AgencyDTO>(iDbContext);
                var catExists     = catRepository
                                    .Query()
                                    .Filter(bp => bp.AgencyName == agency.AgencyName && bp.Id != agency.Id)
                                    .Get()
                                    .FirstOrDefault();
                if (catExists != null)
                {
                    objectExists = true;
                }
            }
            finally
            {
                iDbContext.Dispose();
            }

            return(objectExists);
        }
Exemplo n.º 2
0
        public string Guide_AgencyGetAllByRole(string d, string ri, string w)
        {
            DateTime?date = null;

            try
            {
                date = DateTime.ParseExact(d, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            }
            catch { }
            var routeId = -1;

            try
            {
                routeId = Int32.Parse(ri);
            }
            catch { }
            var way            = w;
            var route          = TransferRequestByDateBLL.RouteGetById(routeId);
            var role           = TransferRequestByDateBLL.RoleGetByName("Guides");
            var listGuide      = TransferRequestByDateBLL.AgencyGetAllByRole(role).Future().ToList();
            var listGuideInDay = TransferRequestByDateBLL.Guide_AgencyGetAllGuideInDay(role, date, route).Future().ToList();
            var listGuideDTO   = new List <AgencyDTO>();

            listGuide.ForEach(guide =>
            {
                var guideInDay            = listGuideInDay.Where(x => x.Id == guide.Id).FirstOrDefault();
                Expense guideExpenseInDay = null;
                if (guideInDay != null)
                {
                    guideExpenseInDay = TransferRequestByDateBLL.ExpenseGetAllByCriterion(guide, date, route)
                                        .Future().SingleOrDefault();
                }
                var guideDTO = new AgencyDTO()
                {
                    Id    = guide.Id,
                    Name  = guideExpenseInDay != null ? guideExpenseInDay.Guide.Name + " - " + guideExpenseInDay.Cruise.Code : guide.Name,
                    Group = guideInDay != null ? "Guide in day" : null,
                };
                listGuideDTO.Add(guideDTO);
            });
            if (way == "Back")
            {
                var listGuideDayBefore = TransferRequestByDateBLL.Guide_AgencyGetAllGuideInDay(role, date.Value.AddDays(-1), route).Future().ToList();
                listGuideDayBefore.ForEach(guideDayBefore =>
                {
                    var guideDTO = new AgencyDTO()
                    {
                        Id    = guideDayBefore.Id,
                        Name  = guideDayBefore.Name,
                        Group = guideDayBefore != null ? "Guide day before" : null,
                    };
                    listGuideDTO.Add(guideDTO);
                });
            }
            Dispose();
            return(JsonConvert.SerializeObject(listGuideDTO));
        }
Exemplo n.º 3
0
 public bool Edit(AgencyDTO AD)
 {
     try
     {
         A_DAL.Edit(AD);
     }
     catch (Exception ex)
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 4
0
        public ServerAgencyViewModel()
        {
            CleanUp();

            var iDbContext = new ServerDbContextFactory().Create();

            _unitOfWork = new UnitOfWorkServer(iDbContext);

            SelectedAgency = new AgencyDTO();
            Agencys        = new ObservableCollection <AgencyDTO>();
            GetLiveAgencys();
            EditCommandVisibility = false;
        }
Exemplo n.º 5
0
    private async void setDate()
    {
        int    _month    = int.Parse(Request["month"]);
        int    agency_fk = int.Parse(Request["agency_fk"]);
        string _total    = Request["total"];

        Year    = Request["year"];
        Agency  = Request["Agency"];
        Address = Request["Address"];

        Date = DateTime.Today.ToString("yyyy-MM-dd");

        Month = DateTimeFormatInfo.CurrentInfo.GetMonthName(_month);

        decimal sum_d = decimal.Parse(_total);

        Sum = String.Format("{0:C}", sum_d);
        decimal base_d = (sum_d / (decimal)1.1);

        Base = String.Format("{0:C}", base_d);
        VAT  = String.Format("{0:C}", (sum_d - base_d));



        using (var client = new HttpClient())
        {
            // New code:
            var api_url = ConfigurationManager.AppSettings["api_url"];
            client.BaseAddress = new Uri(api_url);
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            HttpResponseMessage response = await client.GetAsync("/api/agencies/" + agency_fk);

            if (response.IsSuccessStatusCode)
            {
                AgencyDTO agency = await response.Content.ReadAsAsync <AgencyDTO>();// .ReadAsAsync  ();// .Content.ReadAsAsync > Product > ();

                //}
                Agency  = agency.name;
                Address = agency.address;
            }

            DueDate = DateTime.Today.AddMonths(1).ToString("yyyy-MM-dd");
            //= Math.Round(base_d, 2).ToString("");
        }
    }
Exemplo n.º 6
0
        public void GetAgency()
        {
            var role    = Module.RoleGetByName("Cruise Suppliers");
            var agencys = Module.AgencyGetAllByRole(role);
            var list    = new List <AgencyDTO>();

            foreach (Agency r in agencys)
            {
                var agencyDto = new AgencyDTO();
                agencyDto.Id   = r.Id;
                agencyDto.Name = r.Name;
                list.Add(agencyDto);
            }
            HttpContext.Current.Response.ContentType = "application/json";
            HttpContext.Current.Response.Charset     = "utf-8";
            HttpContext.Current.Response.Write(JsonConvert.SerializeObject(list));
        }
Exemplo n.º 7
0
        public string Supplier_AgencyGetAllByRole()
        {
            var role            = TransferRequestByDateBLL.RoleGetByName("Suppliers");
            var listSupplier    = TransferRequestByDateBLL.AgencyGetAllByRole(role).Future().ToList();
            var listSupplierDTO = new List <AgencyDTO>();

            listSupplier.ForEach(supplier =>
            {
                var supplierDTO = new AgencyDTO()
                {
                    Id   = supplier.Id,
                    Name = supplier.Name,
                };
                listSupplierDTO.Add(supplierDTO);
            });
            Dispose();
            return(JsonConvert.SerializeObject(listSupplierDTO));
        }
        public async Task <AgencyDTO> GetAgencyByAgencyNameAsync(string name)
        {
            using (var conn = new SqlConnection(_connectionSettings.DefaultConnection))
            {
                var          result    = new AgencyDTO();
                const string storeproc = @"[dbo].[uspAgenciesGetByName_New]";
                await conn.OpenAsync();

                var dynParm = new
                {
                    name = name
                };
                var rawResult = await conn.QueryAsync <AgencyDTO>(storeproc, dynParm, null, null, CommandType.StoredProcedure);

                result = rawResult.FirstOrDefault();
                return(result);
            }
        }
        public string AgencyGetAllBy(string ui, string f, string t)
        {
            int userId = -1;

            try
            {
                userId = Int32.Parse(ui);
            }
            catch { }

            DateTime?from = null;

            try
            {
                from = DateTime.ParseExact(f, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            }
            catch { }

            DateTime?to = null;

            try
            {
                to = DateTime.ParseExact(t, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            }
            catch { }

            var listAgency    = ViewActivitiesBLL.AgencyGetAllBy(userId, from, to);
            var listAgencyDTO = new List <AgencyDTO>();

            foreach (var agency in listAgency)
            {
                var agencyDTO = new AgencyDTO()
                {
                    Id       = agency.Id.ToString(),
                    Name     = agency.Name,
                    Phone    = agency.Phone,
                    Fax      = agency.Fax,
                    Email    = agency.Email,
                    RoleName = agency.Role.Name,
                };
                listAgencyDTO.Add(agencyDTO);
            }
            return(JsonConvert.SerializeObject(listAgencyDTO));
        }
Exemplo n.º 10
0
        protected void function_insert_Click(object sender, EventArgs e)
        {
            AgencyDTO ALO = new AgencyDTO();

            ALO.NAME_AGENCY = input_NameAgency.Text;
            ALO.ADDR        = input_Addr.Text;
            ALO.NUMPHONE    = input_Numphone.Text;
            ALO.ACTIVATE    = Int32.Parse(rdo_Activate.SelectedValue.ToString());
            if (ABL.Insert(ALO) == true)
            {
                MessageBox("Thêm thành công", "Agency.aspx");
                uploadData();
            }
            else
            {
                MessageBox("Thêm không thành công", "Agency.aspx");
                uploadData();
            }
        }
Exemplo n.º 11
0
        protected void btn_edit_Click(object sender, EventArgs e)
        {
            AgencyDTO ALO = new AgencyDTO();


            ALO.NAME_AGENCY = input_name.Text;
            ALO.ADDR        = input_addr.Text;
            ALO.NUMPHONE    = input_numphone.Text;
            ALO.ACTIVATE    = Int32.Parse(rdo_Activate.SelectedValue.ToString());
            ALO.ID_AGENCY   = input_id.Text;

            if (ABL.Edit(ALO) == true)
            {
                MessageBox("Sửa thành công", "Agency.aspx");
            }
            else
            {
                MessageBox("Sửa không thành công", "Agency.aspx");
            }
        }
Exemplo n.º 12
0
 public void Insert(AgencyDTO TOP)
 {
     ConnectDB.con.Open();
     try
     {
         SqlCommand cmd = new SqlCommand("insert_Agency", ConnectDB.con);
         cmd.Parameters.Add("@NAME_AGENCY", SqlDbType.NVarChar).Value = TOP.NAME_AGENCY;
         cmd.Parameters.Add("@ADDR", SqlDbType.NVarChar).Value        = TOP.ADDR;
         cmd.Parameters.Add("@NUMPHONE", SqlDbType.VarChar).Value     = TOP.NUMPHONE;
         cmd.Parameters.Add("@ACTIVATE", SqlDbType.Int).Value         = TOP.ACTIVATE;
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.ExecuteNonQuery();
     }
     catch
     {
         throw;
     }
     finally
     {
         ConnectDB.con.Close();
     }
 }
Exemplo n.º 13
0
        public string InsertOrUpdate(AgencyDTO agency)
        {
            string stat;

            try
            {
                var validate = Validate(agency);
                if (!string.IsNullOrEmpty(validate))
                {
                    stat = validate;
                }
                else
                {
                    if (ObjectExists(agency))
                    {
                        stat = GenericMessages.DatabaseErrorRecordAlreadyExists;
                    }
                    else
                    {
                        agency.Synced = false;
                        _localAgencyRepository.InsertUpdate(agency);
                        _unitOfWork.Commit();
                        stat = string.Empty;
                    }
                }
            }
            catch (Exception exception)
            {
                stat = exception.Message;
            }
            finally
            {
                Dispose(_disposeWhenDone);
            }
            return(stat);
        }
Exemplo n.º 14
0
        public string Validate(AgencyDTO agency)
        {
            if (agency == null)
            {
                return(GenericMessages.ObjectIsNull);
            }

            if (agency.Address == null)
            {
                return("Address " + GenericMessages.ObjectIsNull);
            }

            if (String.IsNullOrEmpty(agency.AgencyName))
            {
                return(agency.AgencyName + " " + GenericMessages.StringIsNullOrEmpty);
            }

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

            return(string.Empty);
        }
Exemplo n.º 15
0
        public bool SyncAgencies(IUnitOfWork sourceUnitOfWork, IUnitOfWork destinationUnitOfWork)
        {
            var sourceList = sourceUnitOfWork.Repository <AgencyDTO>().Query()
                             .Include(h => h.Header, h => h.Footer, h => h.Address)
                             .Filter(a => !a.Synced && a.DateLastModified > LastServerSyncDate)
                             .Get(1)
                             .ToList();

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

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

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

                    var clientId = 0;
                    if (destination == null)
                    {
                        destination = new AgencyDTO();
                    }
                    else
                    {
                        clientId = destination.Id;
                    }

                    try
                    {
                        Mapper.Reset();
                        Mapper.CreateMap <AgencyDTO, AgencyDTO>()
                        .ForMember("Address", option => option.Ignore())
                        .ForMember("Header", option => option.Ignore())
                        .ForMember("Footer", option => option.Ignore())
                        .ForMember("Synced", option => option.Ignore());
                        destination    = Mapper.Map(source, destination);
                        destination.Id = clientId;

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

                        var categoryDto =
                            destAddresses.FirstOrDefault(
                                c => source.Address != null && c.RowGuid == source.Address.RowGuid);
                        {
                            destination.Address   = categoryDto;
                            destination.AddressId = categoryDto != null ? categoryDto.Id : (int?)null;
                        }

                        var headerDto =
                            destHeadersFooters.FirstOrDefault(
                                c => source.Header != null && c.RowGuid == source.Header.RowGuid);
                        {
                            destination.Header   = headerDto;
                            destination.HeaderId = headerDto != null ? headerDto.Id : (int?)null;
                        }

                        var footerDto =
                            destHeadersFooters.FirstOrDefault(
                                c => source.Footer != null && c.RowGuid == source.Footer.RowGuid);
                        {
                            destination.Footer   = footerDto;
                            destination.FooterId = footerDto != null ? footerDto.Id : (int?)null;
                        }

                        #endregion

                        destination.Synced = true;
                        destinationUnitOfWork.Repository <AgencyDTO>()
                        .InsertUpdate(destination);
                    }
                    catch
                    {
                        _errorsFound = true;
                        LogUtil.LogError(ErrorSeverity.Critical, "SyncAgencies Crud",
                                         "Problem On SyncAgencies Crud Method", UserName, Agency);
                        return(false);
                    }
                }
                var changes = destinationUnitOfWork.Commit();
                if (changes < 0)
                {
                    _errorsFound = true;
                    LogUtil.LogError(ErrorSeverity.Critical, "SyncAgencies Commit",
                                     "Problem Commiting SyncAgencies Method", UserName, Agency);
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 16
0
 private void ExecuteAddNewAgencyViewCommand()
 {
     SelectedAgency = new AgencyDTO();
 }
Exemplo n.º 17
0
        public bool SyncAgencies2(IUnitOfWork sourceUnitOfWork,
                                  IUnitOfWork destinationUnitOfWork)
        {
            var sourceList = sourceUnitOfWork.Repository <AgencyDTO>().Query()
                             .Filter(a => !a.Synced && a.DateLastModified > LastServerSyncDate)
                             .Get(1)
                             .ToList();

            if (sourceList.Any())
            {
                _updatesFound = true;

                //List<AgencyDTO> destList;

                //if(Singleton.Agency!=null)
                // destList =
                //    destinationUnitOfWork.Repository<AgencyDTO>().Query()
                //        .Include(a => a.Address).Filter(a => a.Id == Singleton.Agency.Id)
                //        .Get(1)
                //        .ToList();
                //else destList =
                //   destinationUnitOfWork.Repository<AgencyDTO>().Query()
                //       .Include(a => a.Address)
                //       .Get(1)
                //       .ToList();

                foreach (var source in sourceList)
                {
                    AgencyDTO source1     = source;
                    var       destination =
                        destinationUnitOfWork.Repository <AgencyDTO>().Query()
                        .Filter(i => i.RowGuid == source1.RowGuid)
                        .Include(a => a.Address)
                        .Get(1).FirstOrDefault();

                    const int clientId = 0;
                    if (destination == null)
                    {
                        destination = new AgencyDTO();
                    }
                    else
                    {
                        continue;//clientId = destination.Id;
                    }
                    try
                    {
                        Mapper.Reset();
                        Mapper.CreateMap <AgencyDTO, AgencyDTO>()
                        .ForMember("Address", option => option.Ignore())
                        .ForMember("Header", option => option.Ignore())
                        .ForMember("Footer", option => option.Ignore())
                        .ForMember("AddressId", option => option.Ignore())
                        .ForMember("HeaderId", option => option.Ignore())
                        .ForMember("FooterId", option => option.Ignore())
                        .ForMember("Synced", option => option.Ignore());
                        destination    = Mapper.Map(source, destination);
                        destination.Id = clientId;

                        destination.Address   = null;
                        destination.AddressId = null;
                        destination.Header    = null;
                        destination.HeaderId  = null;
                        destination.Footer    = null;
                        destination.FooterId  = null;

                        destination.CreatedByUserId = GetDestCreatedModifiedByUserId(source.CreatedByUserId,
                                                                                     sourceUnitOfWork, destinationUnitOfWork);
                        destination.ModifiedByUserId = GetDestCreatedModifiedByUserId(source.ModifiedByUserId,
                                                                                      sourceUnitOfWork, destinationUnitOfWork);
                    }
                    catch (Exception ex)
                    {
                        LogUtil.LogError(ErrorSeverity.Critical, "SyncAgencies Mapping",
                                         ex.Message + Environment.NewLine + ex.InnerException, UserName, Agency);
                        //UpdatingText = "Problem mapping AgencyDTO";
                    }
                    try
                    {
                        destination.Synced = true;
                        destinationUnitOfWork.Repository <AgencyDTO>()
                        .InsertUpdate(destination);
                    }
                    catch
                    {
                        _errorsFound = true;
                        LogUtil.LogError(ErrorSeverity.Critical, "SyncAgencies Crud",
                                         "Problem On SyncAgencies Crud Method", UserName, Agency);
                        return(false);
                    }
                }
                var changes = destinationUnitOfWork.Commit();
                if (changes < 0)
                {
                    _errorsFound = true;
                    LogUtil.LogError(ErrorSeverity.Critical, "SyncAgencies Commit",
                                     "Problem Commiting SyncAgencies Method", UserName, Agency);
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 18
0
        private void DoWork(object sender, DoWorkEventArgs e)
        {
            ProductActivation.ProductKey = ProductKey;
            var key = _dbContext.ActivationKeys
                      .FirstOrDefault(a => a.ProductKey == ProductActivation.ProductKey &&
                                      a.KeyStatus == 0 && a.ProductType == 0);

            //O represents Active and O represents PinnaFace

            if (key != null)
            {
                try
                {
                    if (string.IsNullOrEmpty(key.BIOS_SN))
                    {
                        key.BIOS_SN = ProductActivation.BiosSn;
                        //key.FirstActivatedDate = DateTime.Now;
                        //    //GETUTCDATETIME StoredPr. //the time will be better if it is the server timer
                        //key.ExpirationDate = key.FirstActivatedDate.Value.AddDays(key.ExpiryDuration);
                    }
                    else
                    {
                        if (!key.BIOS_SN.Contains(ProductActivation.BiosSn))
                        {
                            if (key.NoOfAllowedPcs == 1)
                            {
                                MessageBox.Show(
                                    "Can't Activate the product, " +
                                    "Check your product key and try again, " +
                                    "or contact pinnaface office!", "More than Allowed Pcs");
                                ProductKey        = "";
                                CommandsEnability = true;

                                return;
                            }

                            key.BIOS_SN = key.BIOS_SN + "," + ProductActivation.BiosSn;
                            if (key.BIOS_SN.Split(',').Count() > key.NoOfAllowedPcs)
                            {
                                MessageBox.Show(
                                    "Can't Activate the product, " +
                                    "Check your product key and try again, " +
                                    "or contact pinnaface office!", "More than Allowed Pcs");
                                ProductKey        = "";
                                CommandsEnability = true;
                                return;
                            }
                        }
                    }

                    key.NoOfActivations = key.NoOfActivations + 1;
                    if (key.NoOfActivations > key.NoOfAllowedActivations)
                    {
                        MessageBox.Show(
                            "Can't Activate the product, " +
                            "Check your product key and try again, " +
                            "or contact pinnaface office!", "More than Allowed Activations");
                        ProductKey        = "";
                        CommandsEnability = true;
                        return;
                    }

                    _dbContext.Add(key);
                    _dbContext.SaveChanges();

                    ProductActivation.RegisteredBiosSn = key.BIOS_SN;
                    ProductActivation.DateLastModified = DbCommandUtil.GetCurrentSqlDate(true);//  DateTime.Now; //GETUTCDATETIME StoredPr
                    ProductActivation.Synced           = false;

                    if (ProductActivation.Id == 0)
                    {
                        ProductActivation.LicensedTo           = key.CustomerName;
                        ProductActivation.DatabaseVersionDate  = Singleton.SystemVersionDate;
                        ProductActivation.MaximumSystemVersion = key.MaximumAllowedSystemVersion;


                        ProductActivation.ModifiedByUserId  = 1;
                        ProductActivation.CreatedByUserId   = 1;
                        ProductActivation.DateRecordCreated = DbCommandUtil.GetCurrentSqlDate(true);//DateTime.Now; //GETUTCDATETIME StoredPr

                        #region Set UserAccounts

                        ProductActivation.SuperName = key.SuperName; //.Email;
                        ProductActivation.SuperPass = key.SuperPass;
                        ProductActivation.AdminName = key.AdminName;
                        ProductActivation.AdminPass = key.AdminPass;
                        ProductActivation.User1Name = key.User1Name;
                        ProductActivation.User1Pass = key.User1Pass;

                        #endregion

                        #region Agency

                        var localAgency = new AgencyDTO
                        {
                            AgencyName         = key.CustomerName ?? (key.CustomerName = ""),
                            AgencyNameAmharic  = "-",
                            ManagerName        = "-",
                            ManagerNameAmharic = "-",
                            Address            = new AddressDTO
                            {
                                AddressType  = AddressTypes.Local,
                                Country      = CountryList.Ethiopia,
                                City         = EnumUtil.GetEnumDesc(CityList.AddisAbeba),
                                Region       = "14",
                                Telephone    = key.Telephone ?? (key.Telephone = ""),
                                PrimaryEmail = key.Email ?? (key.Email = "")
                            },
                            Header           = new AttachmentDTO(),
                            Footer           = new AttachmentDTO(),
                            LicenceNumber    = "-",
                            SaudiOperation   = key.SaudiOperation,
                            DubaiOperation   = key.DubaiOperation,
                            KuwaitOperation  = key.KuwaitOperation,
                            QatarOperation   = key.QatarOperation,
                            JordanOperation  = key.JordanOperation,
                            LebanonOperation = key.LebanonOperation,
                            BahrainOperation = key.BahrainOperation,
                            DepositAmount    = "100,000 USD",
                            Managertype      = "ዋና ስራ አስኪያጅ"
                        };

                        #endregion

                        #region Foreign Agents

                        var foreignAgent = new AgentDTO
                        {
                            AgentName        = "-",
                            AgentNameAmharic = "-",
                            Address          = new AddressDTO
                            {
                                AddressType = AddressTypes.Foreign,
                                Country     = CountryList.SaudiArabia,
                                City        = EnumUtil.GetEnumDesc(CityList.Riyadh)
                            },
                            LicenseNumber = "-",
                            Header        = new AttachmentDTO(),
                            Footer        = new AttachmentDTO(),
                        };

                        #endregion

                        #region Setting

                        var setting = new SettingDTO
                        {
                            AwajNumber             = "923/2008",
                            EmbassyApplicationType = EmbassyApplicationTypes.SponsorNameOnTop,
                            SyncDuration           = 1,
                            StartSync = true,
                        };

                        #endregion

                        ProductActivation.FirstActivatedDate = key.FirstActivatedDate; // DateTime.Now; //GETUTCDATETIME StoredPr
                        ProductActivation.ExpiryDate         = key.ExpiryDate;         // DateTime.Now.AddDays(key.ExpiryDuration);

                        ProductActivation.Agency = localAgency;
                        setting.Agency           = localAgency;

                        ////Since we don't update Header and Footer from Server we didnt need the following 6 lines
                        //localAgency.Address.Agency = localAgency;
                        //localAgency.Header.Agency = localAgency;
                        //localAgency.Footer.Agency = localAgency;

                        //foreignAgent.Address.Agency = localAgency;
                        //foreignAgent.Header.Agency = localAgency;
                        //foreignAgent.Footer.Agency = localAgency;

                        _unitOfWork.Repository <AgencyDTO>().Insert(localAgency);
                        _unitOfWork.Repository <AgentDTO>().Insert(foreignAgent);

                        _unitOfWork.Repository <SettingDTO>().Insert(setting);
                        _unitOfWork.Repository <ProductActivationDTO>().Insert(ProductActivation);
                    }
                    else
                    {
                        //localAgency.Synced = false;
                        //foreignAgent.Synced = false;

                        //_unitOfWork.Repository<AgencyDTO>().Update(localAgency);
                        //_unitOfWork.Repository<AgentDTO>().Update(foreignAgent);

                        _unitOfWork.Repository <ProductActivationDTO>().Update(ProductActivation);
                    }

                    int changes = _unitOfWork.Commit();
                    if (changes > 0)
                    {
                        Singleton.ProductActivation = ProductActivation;
                        _login = true;
                    }
                    else
                    {
                        MessageBox.Show(
                            "Can't Activate the product, check your product key and try again, or contact pinnasofts!");
                        ProductKey        = "";
                        CommandsEnability = true;
                    }
                }
                catch
                {
                    MessageBox.Show("Error:" + Environment.NewLine + " There may be no Internet connection." +
                                    Environment.NewLine + "Check your connection and try again.");
                    CommandsEnability = true;
                }
            }
            else
            {
                MessageBox.Show(
                    "Can't Activate the product, check your product key and try again, or contact pinnasofts!");
                ProductKey        = "";
                CommandsEnability = true;
            }
        }