Ejemplo n.º 1
0
        public ActionResult AddSourceDetails(SourceDetailModel model)
        {
            bool   userLoggedin = (System.Web.HttpContext.Current.User != null) && System.Web.HttpContext.Current.User.Identity.IsAuthenticated;
            string userid       = "";

            if (ModelState.IsValid)
            {
                if (userLoggedin)
                {
                    userid = System.Web.HttpContext.Current.User.Identity.GetUserId();
                    var customer = InsuranceContext.Customers.Single(where : $"UserId ='{userid}'");
                    var dbModel  = Mapper.Map <SourceDetailModel, SourceDetail>(model);
                    dbModel.CreatedOn  = DateTime.Now;
                    dbModel.CreatedBy  = customer.Id;
                    dbModel.BusinessId = Convert.ToInt32(model.Source);
                    dbModel.IsDeleted  = true;
                    InsuranceContext.SourceDetails.Insert(dbModel);
                    return(RedirectToAction("SourceDetailsList"));
                }
            }

            else
            {
                foreach (ModelState modelState in ViewData.ModelState.Values)
                {
                    foreach (ModelError error in modelState.Errors)
                    {
                        var result = "";
                    }
                }
            }
            return(View());
        }
Ejemplo n.º 2
0
 public ActionResult EditSourceDetail(SourceDetailModel model)
 {
     if (ModelState.IsValid)
     {
         string userid   = System.Web.HttpContext.Current.User.Identity.GetUserId();
         var    customer = InsuranceContext.Customers.Single(where : $"UserId ='{userid}'");
         var    data     = Mapper.Map <SourceDetailModel, SourceDetail>(model);
         data.ModifiedOn = DateTime.Now;
         data.ModifiedBy = Convert.ToInt32(customer.Id);
         data.IsDeleted  = true;
         InsuranceContext.SourceDetails.Update(data);
         return(RedirectToAction("SourceDetailsList"));
     }
     return(View());
 }