public ActionResult DolarMedioCreateConfirmed(DolarMedio dolarmedio)
        {
            try
            {
                dolarmedio = ObtemDolarMedioForm(dolarmedio, true);

                if (ModelState.IsValid)
                {
                    DolarMedio dolarmedioExiste = new DolarMedio();
                    dolarmedioExiste = null;

                    dolarmedioExiste = DolarMedioVigente(dolarmedio);

                    if (dolarmedioExiste == null)
                    {
                        _dolarmedioAppService.Create(dolarmedio);
                    }
                    else
                    {
                        throw new InvalidOperationException("Já existe um perído vigente e ativo que coincide com a tentativa de inclusão / alteração");
                    }

                    return RedirectToAction("DolarMedioIndex");
                }
            }
            catch (RetryLimitExceededException /* dex */)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Erro ao salvar. Tente novamente ou, se o problema persistir, entre em contato com o suporte.");
            }

            return View(dolarmedio);
        }
        // GET: /DolarMedio/DolarMedioCreate
        public ActionResult DolarMedioCreate()
        {
            DolarMedio dolarmedio = new DolarMedio();

            #region populaobjetos
            var planos = _planoAppService.Find(t => t.STATUS == "A"); ;
            IEnumerable<SelectListItem> planosSelectListItem = new SelectList(planos, "ID_PLANO", "DESC_PLANO");
            ViewBag.CODIGOLOJAALTERNATE = new SelectList(planos, "ID_PLANO", "DESC_PLANO");
            #endregion populaobjetos

            DolarMedioViewModel dolarmedioVM = new DolarMedioViewModel(dolarmedio, planosSelectListItem);

            return View(dolarmedioVM);
        }
 public DolarMedioViewModel(DolarMedio dolarMedio, IEnumerable<SelectListItem> planosSelectListItem)
 {
     DolarMedio = dolarMedio;
     PlanosSelectListItem = planosSelectListItem;
 }
 public DolarMedioViewModel(DolarMedio dolarMedio)
 {
     DolarMedio = dolarMedio;
 }
        private DolarMedio ObtemDolarMedioForm(DolarMedio dm, bool insert = false)
        {
            dm.ID_PLANO = Convert.ToInt32(Request["DolarMedio.ID_PLANO"]);
            dm.TIPO_TAXA = Request["DolarMedio.TIPO_TAXA"];
            dm.VALOR_DOLAR_MEDIO = Convert.ToDecimal(Request["DolarMedio.VALOR_DOLAR_MEDIO"]);
            dm.DT_INI = Convert.ToDateTime(Request["DolarMedio.DT_INI"]);
            dm.DT_FIM = Convert.ToDateTime(Request["DolarMedio.DT_FIM"]);

            dm.LAST_MODIFY_DATE = DateTime.Now;
            dm.LAST_MODIFY_USERNAME = _controleacessoAppService.ObtainCurrentLoginFromAd();

            if (insert)
            {
                dm.CREATED_DATETIME = dm.LAST_MODIFY_DATE;
                dm.CREATED_USERNAME = dm.LAST_MODIFY_USERNAME;
            }

            return dm;
        }
 private DolarMedio DolarMedioVigente(DolarMedio dm)
 {
     return _dolarmedioAppService.Find(t => t.ID_PLANO == dm.ID_PLANO
                                         && (
                                             (t.DT_INI <= dm.DT_INI && t.DT_FIM >= dm.DT_INI)
                                             || (t.DT_FIM <= dm.DT_INI && t.DT_FIM >= dm.DT_FIM)
                                             || (dm.DT_INI <= t.DT_INI && dm.DT_FIM >= t.DT_FIM)
                                         )
                                     ).FirstOrDefault();
 }
        public ActionResult DolarMedioEditConfirmed(int? id)
        {
            if (id == null)
            {
                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                throw new Exception();
            }

            var dolarmedioToUpdate = _dolarmedioAppService.Get(id ?? default(int));

            dolarmedioToUpdate = ObtemDolarMedioForm(dolarmedioToUpdate);

            if (ModelState.IsValid)
            {
                try
                {
                    DolarMedio dolarmedioExiste = new DolarMedio();
                    dolarmedioExiste = null;

                    dolarmedioExiste = DolarMedioVigente(dolarmedioToUpdate);

                    if (dolarmedioExiste == null)
                    {
                        _dolarmedioAppService.Update(dolarmedioToUpdate);
                    }
                    else
                    {
                        throw new InvalidOperationException("Já existe um perído vigente que coincide com a tentativa de inclusão / alteração");
                    }

                    return RedirectToAction("DolarMedioIndex");
                }
                catch (RetryLimitExceededException /* dex */)
                {
                    //Log the error (uncomment dex variable name and add a line here to write a log.
                    ModelState.AddModelError("", "Erro na alteração. Tente novamente ou, se o problema persistir, entre em contato com o suporte.");
                }
            }

            return View(dolarmedioToUpdate);
        }