Ejemplo n.º 1
0
        public ActionResult Create()
        {
            var viewmodel = new BarAddViewModel();

            viewmodel.AvailableDbSources = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text = DbSource.GC.ToString(), Value = ((int)DbSource.GC).ToString()
                },
                new SelectListItem()
                {
                    Text = DbSource.DIST.ToString(), Value = ((int)DbSource.DIST).ToString()
                }
            };
            viewmodel.AvailableBarNumberTargets = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text = BarNumberTarget.Debit.ToString(), Value = ((int)BarNumberTarget.Debit).ToString()
                },
                new SelectListItem()
                {
                    Text = BarNumberTarget.Credit.ToString(), Value = ((int)BarNumberTarget.Credit).ToString()
                }
            };
            return(View(viewmodel));
        }
Ejemplo n.º 2
0
        public ActionResult Create(BarAddViewModel viewmodel)
        {
            if (ModelState.IsValid)
            {
                if (!_barService.GetAllBars(viewmodel.Year.Value, viewmodel.DisplayName, viewmodel.BarNumber, null, viewmodel.DbSource).Any())
                {
                    var entity = Mapper.Map <BarAddViewModel, Bar>(viewmodel);
                    if (string.IsNullOrWhiteSpace(entity.MapToBarNumber))
                    {
                        entity.MapToBarNumber = entity.BarNumber;
                    }

                    if (entity.DbSource != DbSource.DIST)
                    {
                        entity.BarTarget = null;
                    }

                    _barService.Add(new List <Bar>()
                    {
                        entity
                    });

                    Success($"<strong>{entity.DisplayName} - {entity.BarNumber}</strong> was successfully saved.");
                    return(RedirectToAction("Index", new { year = entity.Year, dbsource = entity.DbSource }));
                }
                else
                {
                    Danger($"A bar with same Number <strong>{viewmodel.BarNumber}</strong> already exists within the same year <strong>{viewmodel.Year.Value}</strong>.");
                }
            }
            viewmodel.AvailableDbSources = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text = DbSource.GC.ToString(), Value = ((int)DbSource.GC).ToString()
                },
                new SelectListItem()
                {
                    Text = DbSource.DIST.ToString(), Value = ((int)DbSource.DIST).ToString()
                }
            };
            viewmodel.AvailableBarNumberTargets = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text = BarNumberTarget.Debit.ToString(), Value = ((int)BarNumberTarget.Debit).ToString()
                },
                new SelectListItem()
                {
                    Text = BarNumberTarget.Credit.ToString(), Value = ((int)BarNumberTarget.Credit).ToString()
                }
            };
            return(View(viewmodel));
        }