Esempio n. 1
0
        public void Settings(string pageTab)
        {
            var defaults = Defaults;
            NewSupplierMessage newSupplierMessage = new NewSupplierMessage();

            if (IsPost)
            {
                ((ARDataBinder)Binder).AutoLoad = AutoLoadBehavior.Always;
                BindObjectInstance(defaults, ParamStore.Form, "defaults");
                if (IsValid(defaults))
                {
                    newSupplierMessage.CreateEmlFile(defaults);
                    Notify("Сохранено");
                    RedirectToUrl(Request.UrlReferrer + pageTab);
                }
                else
                {
                    ActiveRecordMediator.Evict(defaults);
                    PropertyBag["Defaults"]  = defaults;
                    PropertyBag["Formaters"] = OrderHandler.Formaters();
                    PropertyBag["Senders"]   = OrderHandler.Senders();
                }
            }
            else
            {
                PropertyBag["Defaults"]  = defaults;
                PropertyBag["Formaters"] = OrderHandler.Formaters();
                PropertyBag["Senders"]   = OrderHandler.Senders();
            }
        }
        public void Evict(T entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            ActiveRecordMediator.Evict(entity);
        }
Esempio n. 3
0
        public void EditCatalogs(
            uint id,
            [DataBind("filter")] CatalogFilter filter)
        {
            var promotion = DbSession.Load <SupplierPromotion>(id);

            PropertyBag["promotion"] = promotion;

            filter.Promotion            = promotion;
            PropertyBag["filter"]       = filter;
            PropertyBag["catalogNames"] = filter.Find <Catalog>();

            if (IsPost)
            {
                if (Request.Params["delBtn"] != null)
                {
                    foreach (string key in Request.Params.AllKeys)
                    {
                        if (key.StartsWith("chd"))
                        {
                            var catalog = DbSession.Load <Catalog>(Convert.ToUInt32(Request.Params[key]));
                            var index   = promotion.Catalogs.IndexOf(c => c.Id == catalog.Id);
                            if (index >= 0)
                            {
                                promotion.Catalogs.RemoveAt(index);
                            }
                        }
                    }
                }

                if (Request.Params["addBtn"] != null)
                {
                    foreach (string key in Request.Params.AllKeys)
                    {
                        if (key.StartsWith("cha"))
                        {
                            var catalog = DbSession.Load <Catalog>(Convert.ToUInt32(Request.Params[key]));

                            if (promotion.Catalogs.FirstOrDefault(c => c.Id == catalog.Id) == null)
                            {
                                promotion.Catalogs.Add(catalog);
                            }
                        }
                    }
                }

                ActiveRecordMediator.Evict(promotion);
                if (Validator.IsValid(promotion) && promotion.Catalogs.Count > 0)
                {
                    Notify("Сохранено");
                    promotion.UpdateStatus();
                    DbSession.Update(promotion);
                    RedirectToAction("EditCatalogs", filter.ToUrl());
                }
                else
                {
                    var summary = String.Empty;
                    if (Validator.GetErrorSummary(promotion) != null)
                    {
                        summary = String.Join(Environment.NewLine, Validator.GetErrorSummary(promotion).ErrorMessages);
                    }

                    if (promotion.Catalogs.Count == 0)
                    {
                        summary = String.Join(Environment.NewLine, summary, "Список препаратов не может быть пустым.");
                    }

                    Error(summary);
                    ActiveRecordMediator.Evict(promotion);
                    var discardedPromotion = DbSession.Load <SupplierPromotion>(id);
                    PropertyBag["promotion"] = discardedPromotion;
                }
            }
        }
Esempio n. 4
0
        public void Edit(uint id, [DataBind("PromoRegions")] ulong[] promoRegions, bool deleteOnSave = false)
        {
            PropertyBag["allowedExtentions"] = GetAllowedExtentions();
            Binder.Validator = Validator;

            var promotion = DbSession.Load <SupplierPromotion>(id);

            PropertyBag["promotion"]  = promotion;
            PropertyBag["isOverdued"] = promotion.End < SystemTime.Now();
            ActiveRecordMediator.Evict(promotion);
            PropertyBag["AllowRegions"] = Region.GetRegionsByMask(DbSession, promotion.PromotionOwnerSupplier.MaskRegion).OrderBy(reg => reg.Name);


            if (IsPost)
            {
                promotion.RegionMask = promoRegions.Aggregate(0UL, (v, a) => a + v);

                BindObjectInstance(promotion, "promotion");
                promotion.UpdateStatus();

                if (IsValid(promotion))
                {
                    if (deleteOnSave)
                    {
                        var oldLocalPromoFile = GetPromoFile(promotion);
                        if (File.Exists(oldLocalPromoFile))
                        {
                            File.Delete(oldLocalPromoFile);
                        }
                        promotion.PromoFile = null;
                    }
                    else
                    {
                        var file = Request.Files["inputfile"] as HttpPostedFile;
                        if (file != null && file.ContentLength > 0)
                        {
                            if (!IsAllowedExtention(Path.GetExtension(file.FileName)))
                            {
                                Error("Выбранный файл имеет недопустимый формат.");
                                return;
                            }

                            var oldLocalPromoFile = GetPromoFile(promotion);
                            if (File.Exists(oldLocalPromoFile))
                            {
                                File.Delete(oldLocalPromoFile);
                            }

                            promotion.PromoFile = file.FileName;

                            var newLocalPromoFile = GetPromoFile(promotion);
                            using (var newFile = File.Create(newLocalPromoFile)) {
                                file.InputStream.CopyTo(newFile);
                            }
                        }
                    }

                    promotion.UpdateStatus();
                    DbSession.Update(promotion);
                    SendNotificationAboutUpdatePromotion(promotion);
                    RedirectToAction("Index");
                }
                else
                {
                    ActiveRecordMediator.Evict(promotion);
                }
            }
            else
            {
                ActiveRecordMediator.Evict(promotion);
            }
        }