Пример #1
0
 public ActionResult Edit(DistributorViewModel model)
 {
     if (ModelState.IsValid)
     {
         if (model.Parent == Guid.Empty)
         {
             // Add new
             var         parentUser  = Session["UserData"] as User;
             Distributor distributor = Mapper.Map <DistributorViewModel, Distributor>(model);
             distributor.Parent = parentUser.UserId;
             _distributorService.CreateDistributor(distributor);
         }
         else
         {
             model.Password = "******";
             try
             {
                 Distributor distributor = _distributorService.GetUser(model.UserId);
                 Mapper.Map <DistributorViewModel, Distributor>(model, distributor);
                 _distributorService.UpdateUser(distributor);
             }
             catch (Exception ex)
             {
                 ModelState.AddModelError("Error", ex.Message);
             }
         }
         _distributorService.SaveDistributor();
     }
     else
     {
     }
     return(Json(new { Result = "Success" }));
 }