예제 #1
0
        public ActionResult GetIp(int?rowIp)
        {
            CountryIPRange countryIpRange;

            if (rowIp == null || rowIp == 0)
            {
                countryIpRange = new CountryIPRange();
            }
            else
            {
                var list = (List <CountryIPRange>)Session["IPList"];
                countryIpRange = list.FirstOrDefault(ipRange => ipRange.Id.Equals(rowIp));
            }
            return(PartialView("PVCountryIP", countryIpRange));
        }
예제 #2
0
        public ActionResult GetIp(FormCollection collection)
        {
            if (string.IsNullOrEmpty(collection["StartRange"]) || string.IsNullOrEmpty(collection["EndRange"]))
            {
                ShowMessage(Resources.CommonComponent.IpIsUnvalid, Resources.Common.MessaageTitle,
                            messageIcon: MessageIcon.Error);
                return(Content("false"));
            }
            var list = (List <CountryIPRange>)Session["IPList"];

            if (list == null)
            {
                return(Content("false"));
            }
            var id = collection["IpId"].ToInt();

            if (id == 0)
            {
                var ip = new CountryIPRange();
                this.RadynTryUpdateModel(ip);
                if (CommonComponent.Instance.CountryIpRangeFacade.ValidateIp(ip))
                {
                    ip.Id = list.Count == 0 ? 1 : list.Max(range => range.Id) + 1;
                    list.Add(ip);
                    return(Content("true"));
                }
                ShowMessage(Resources.CommonComponent.IpIsUnvalid, Resources.Common.MessaageTitle,
                            messageIcon: MessageIcon.Error);
                return(Content("false"));
            }
            var firstOrDefault = list.FirstOrDefault(countryIpRange => countryIpRange.Id.Equals(id));

            if (firstOrDefault != null)
            {
                this.RadynTryUpdateModel(firstOrDefault);
            }
            return(Content("true"));
        }
예제 #3
0
        public bool Update(Country country, List <CountryIPRange> list, HttpPostedFileBase file)
        {
            try
            {
                this.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted);
                this.FileManagerConnection.StartTransaction(IsolationLevel.ReadUncommitted);

                if (file != null)
                {
                    var fileTransactionalFacade =
                        FileManagerComponent.Instance.FileTransactionalFacade(this.FileManagerConnection);
                    if (country.Image.HasValue)
                    {
                        fileTransactionalFacade
                        .Update(file, (Guid)country.Image);
                    }
                    else
                    {
                        country.Image =
                            fileTransactionalFacade
                            .Insert(file);
                    }
                }


                var countryIpRangeBo = new CountryIPRangeBO();
                var countryIpRanges  = countryIpRangeBo.Where(this.ConnectionHandler, x => x.CountryId == country.Id);
                foreach (var countryIpRange in list)
                {
                    CountryIPRange range   = countryIpRange;
                    var            ipRange = countryIpRangeBo.FirstOrDefault(this.ConnectionHandler, x =>

                                                                             x.CountryId == country.Id &&
                                                                             x.Id == range.Id);
                    if (ipRange == null)
                    {
                        countryIpRange.CountryId = country.Id;
                        if (!countryIpRangeBo.Insert(this.ConnectionHandler, countryIpRange))
                        {
                            throw new Exception("خطایی در ذخیره  IP کشور وجود دارد");
                        }
                    }
                    else
                    {
                        if (!countryIpRangeBo.Update(this.ConnectionHandler, countryIpRange))
                        {
                            throw new Exception("خطایی در ذخیره  IP کشور وجود دارد");
                        }
                    }
                }
                foreach (var countryIpRange in countryIpRanges)
                {
                    if (list.Any(x => x.Id == countryIpRange.Id))
                    {
                        continue;
                    }
                    if (!countryIpRangeBo.Delete(this.ConnectionHandler, countryIpRange.Id))
                    {
                        throw new Exception("خطایی در حذف  IP کشور وجود دارد");
                    }
                }
                if (!new CountryBO().Update(this.ConnectionHandler, country))
                {
                    throw new Exception("خطایی در ذخیره کشور وجود دارد");
                }

                this.ConnectionHandler.CommitTransaction();
                this.FileManagerConnection.CommitTransaction();
                return(true);
            }
            catch (KnownException ex)
            {
                this.ConnectionHandler.RollBack();
                this.FileManagerConnection.RollBack();
                Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace);
                throw new KnownException(ex.Message, ex);
            }
            catch (Exception ex)
            {
                this.ConnectionHandler.RollBack();
                this.FileManagerConnection.RollBack();
                Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace);
                throw new KnownException(ex.Message, ex);
            }
        }