Esempio n. 1
0
        public int CreatePeriodical(PeriodicalViewModel periodical)
        {
            var mappedPeriodical = mapper.Map <PeriodicalViewModel, Periodical>(periodical);
            var newId            = db.Periodicals.Create(mappedPeriodical);

            db.Save();
            return(newId);
        }
        public IActionResult Create([FromBody] PeriodicalViewModel Periodical)
        {
            if (Periodical.Foundation <= new DateTime(1970, 1, 1))
            {
                return(BadRequest(new { message = "Release date might be greater than passed" }));
            }
            int id = service.CreatePeriodical(Periodical);

            return(Json(service.GetPeriodicalViewModel(id)));
        }
Esempio n. 3
0
 public PeriodicalControl(MainControl mainControl)
 {
     InitializeComponent();
     DataContext        = null;
     DataContext        = new PeriodicalViewModel(this);
     this.mainControl   = mainControl;
     mainControl.thread = new Thread(new ThreadStart(() =>
     {
         while (true)
         {
             if (ServerSetting.rfid.IsOpen())
             {
                 ServerSetting.rfid.Start();
             }
             this.Dispatcher.BeginInvoke((Action) delegate
             {
                 lock (ServerSetting.EPClist)
                 {
                     if (ServerSetting.EPClist.Count == 0 && string.IsNullOrEmpty(EPC.Text))
                     {
                         BookCode.Text       = "请先扫描RFID";
                         BookCode.IsReadOnly = true;
                         EPC.Clear();
                     }
                     else
                     {
                         if (BookCode.IsReadOnly)
                         {
                             BookCode.IsReadOnly = false;
                             BookCode.Text       = "";
                             BookCode.Focus();
                             lock (ServerSetting.EPClist)
                             {
                                 string epc = ServerSetting.EPClist.Dequeue();
                                 ServerSetting.EPClist.Enqueue(epc);
                                 EPC.Text = epc;
                             }
                         }
                     }
                 }
             });
             Thread.Sleep(500);
         }
     }));
     mainControl.thread.IsBackground = true;
 }
        public ActionResult Create()
        {
            var model = new PeriodicalViewModel
            {
                PublishingHouseSelectList = new ViewModels.SelectList {
                    Items = publishingHouseHelper.GetPublishingHouseSelectList().Select(el => new ViewModels.SelectListItem {
                        Text = el.Text, Value = int.Parse(el.Value), Selected = el.Selected
                    }).ToList()
                },
                PeriodicalTypeSelectList = new ViewModels.SelectList {
                    Items = periodicalHelper.GetPeriodicalTypeViewModelSelectList().Select(el => new ViewModels.SelectListItem {
                        Text = el.Text, Value = int.Parse(el.Value), Selected = el.Selected
                    }).ToList()
                }
            };

            return(View(model));
        }
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var valueProvider = bindingContext.ValueProvider;

            string sPeriodicalId = valueProvider.GetValue("Id")?.AttemptedValue;

            int.TryParse(sPeriodicalId, out int periodicalId);

            string name  = (string)valueProvider.GetValue("Name")?.ConvertTo(typeof(string));
            string issn  = (string)valueProvider.GetValue("ISSN")?.ConvertTo(typeof(string));
            bool   isPub = (bool)valueProvider.GetValue("IsPublished")?.ConvertTo(typeof(bool));
            string sType = valueProvider.GetValue("Type.Id")?.AttemptedValue;

            int.TryParse(sType, out int type);
            DateTime foundation = DateTime.ParseExact(valueProvider.GetValue("Foundation").AttemptedValue, CultureFormatsModule.GetCustomDateFormat(), CultureInfo.InvariantCulture);
            string   sPhId      = valueProvider.GetValue("PublishingHouse.Id")?.AttemptedValue;

            int.TryParse(sPhId, out int phId);

            string authorsRaw = valueProvider.GetValue("Authors")?.AttemptedValue;
            List <AuthorViewModel> authors = authorsRaw?.Split(',').
                                             Select(x => { return(int.TryParse(x, out int id) ? new AuthorViewModel {
                    Id = id
                } : null); })
                                             .Where(x => x != null).ToList() ?? new List <AuthorViewModel>();

            PeriodicalViewModel periodical = new PeriodicalViewModel
            {
                Id                 = periodicalId,
                Name               = name,
                ISSN               = issn,
                Foundation         = foundation,
                IsPublished        = isPub,
                PublishingHouse_Id = phId,
                PublishingHouse    = new PublishingHouseViewModel {
                    Id = phId
                },
                Type = new PeriodicalTypeViewModel {
                    Id = type
                },
            };

            return(periodical);
        }
        public ActionResult Edit(PeriodicalViewModel periodical)
        {
            if (!ModelState.IsValid)
            {
                periodical.PublishingHouseSelectList = new ViewModels.SelectList {
                    Items = publishingHouseHelper.GetPublishingHouseSelectList().Select(el => new ViewModels.SelectListItem {
                        Text = el.Text, Value = int.Parse(el.Value), Selected = el.Selected
                    }).ToList()
                };
                periodical.PeriodicalTypeSelectList = new ViewModels.SelectList {
                    Items = periodicalHelper.GetPeriodicalTypeViewModelSelectList().Select(el => new ViewModels.SelectListItem {
                        Text = el.Text, Value = int.Parse(el.Value), Selected = el.Selected
                    }).ToList()
                };
                return(View(periodical));
            }

            service.UpdatePeriodical(periodical);
            return(RedirectToAction("Details", new { id = periodical.Id }));
        }
Esempio n. 7
0
        public void UpdatePeriodical(PeriodicalViewModel periodical)
        {
            if (periodical.PublishingHouse_Id == 0)
            {
                periodical.PublishingHouse_Id = (int)periodical.PublishingHouse?.Id;
            }
            else
            {
                if (periodical.PublishingHouse == null)
                {
                    periodical.PublishingHouse = new PublishingHouseViewModel {
                        Id = periodical.PublishingHouse_Id
                    };
                }
                else
                {
                    periodical.PublishingHouse.Id = periodical.PublishingHouse_Id;
                }
            }
            var mappedPeriodical = mapper.Map <PeriodicalViewModel, Periodical>(periodical);

            db.Periodicals.Update(mappedPeriodical);
            db.Save();
        }
 public PeriodicalViewModel Edit([FromBody] PeriodicalViewModel Periodical)
 {
     service.UpdatePeriodical(Periodical);
     return(service.GetPeriodicalViewModel(Periodical.Id));
 }