示例#1
0
        public JsonResult AddUserCompany(UserCompanyViewModel model)
        {
            var result = new { Success = "true", Message = "Success" };

            if (ModelState.IsValid)
            {
                var newCompany = Mapper.Map <UserCompany>(model);

                try
                {
                    newCompany.CreatedDate = DateTime.Now;
                    newCompany.UpdatedDate = newCompany.CreatedDate;

                    newCompany.Address.AddressType = _addressService.GetAddressTypeByName(Enumerations.AddressType.Zameldowania.ToString());
                    newCompany.ApplicationUserID   = User.Identity.GetUserId();

                    _userCompanyService.Create(newCompany);
                }
                catch (Exception e)
                {
                    logger.Error(e, e.Message);
                    result = new { Success = "false", Message = WebResources.ErrorMessage };
                }

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var error = ModelState.Values.SelectMany(v => v.Errors).FirstOrDefault().ErrorMessage;

                result = new { Success = "false", Message = error };

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }