public ActionResult Create(CompanyModel data)
        {
            try
            {
                if (HasCompany())
                {
                    return(RedirectToAction("Index"));
                }

                if (ModelState.IsValid)
                {
                    PersonServices PersonServ = new PersonServices();
                    var            userId     = (int)SessionWeb.User.UserId;
                    var            person     = PersonServ.getFirstUserPerson(new UserPersonModel()
                    {
                        UserId = userId
                    }).ToPerson();
                    CompanyServices cs = new CompanyServices();
                    CompanyModel    cm = new CompanyModel()
                    {
                        CompanyName = data.CompanyName,
                        RFC         = data.RFC,
                        Address     = data.Address,
                        PhoneNumber = data.PhoneNumber,
                        Email       = data.Email
                    };
                    var result = cs.AddCompany(cm, person);
                    if (result.Status != Status.Success)
                    {
                        throw new Exception(string.Format("{0}: {1}", localResource.txt_company_error_saved, result.Message));
                    }
                    SessionWeb.User.CompanyId = ((CompanyModel)result.Data).CompanyId;
                    InvitationCompanyServices invServ = new InvitationCompanyServices();
                    foreach (var i in UserPerson.InvitationsCompanies)
                    {
                        i.Status = 2;
                        invServ.InsUpd(i);
                    }
                    return(Json(result));
                }
                return(Json(new RequestResult <object>()
                {
                    Status = Status.Error, Message = localResource.txt_company_error_saved
                }));
            }
            catch (Exception ex)
            {
                Response.StatusCode        = (int)HttpStatusCode.BadRequest;
                Response.StatusDescription = ex.Message;

                return(Json(ex.Message, JsonRequestBehavior.AllowGet));
                //return Json(new RequestResult<object>() { Status = Status.Error, Message = ex.Message });
            }
        }
        public ActionResult Edit(CompanyEdit model)
        {
            //日期格式转换成Unix时间戳格式。
            if (!string.IsNullOrEmpty(model.setDate))
            {
                model.setDate = DateTimeHelper.ConvertDateTimeInt(model.setDate.ToDateTime()).ToString();
            }
            if (model.id > 0)
            {
                //修改
                Entity.ResultEntity updateResult = _cServices.UpdateCompany(model);
                ShowMessageHelper.MessageBoxBackPage("单位信息修改成功");
            }
            else
            {
                //新建
                CompanyAdd entity = new CompanyAdd()
                {
                    unitName = model.unitName,
                    address  = model.address,
                    clientId = model.clientId,
                    cop      = model.cop,
                    fax      = model.fax,
                    tel1     = model.tel1,
                    tel2     = model.tel2,
                    typeId   = model.typeId,
                    gradeSid = model.gradeSid,
                    linkman  = model.linkman,
                    notused  = model.notused,
                    remark   = model.remark,
                    setDate  = model.setDate,
                    setMan   = model.setMan
                };

                ResultAddCompany addResult = _cServices.AddCompany(entity);
                if (addResult != null && addResult.result == "1")
                {
                    model.id     = addResult.id;
                    model.unitId = addResult.unitId;
                    ShowMessageHelper.MessageBoxBackPage("单位信息创建成功");
                }
                else
                {
                    ShowMessageHelper.MessageBoxBackPage("服务器异常,请稍后再试");
                }
            }
            LoadDropDownListData();
            return(View(model));
        }
 private async void ExecuteSaveAsync()
 {
     if (_companyServ.GetCompany(_newCompany.Name) != null)
     {
         await _currentWindow.ShowMessageAsync("فشل الإضافة", "هذه الشركة موجودة مسبقاً", MessageDialogStyle.Affirmative, new MetroDialogSettings()
         {
             AffirmativeButtonText = "موافق",
             DialogMessageFontSize = 25,
             DialogTitleFontSize   = 30
         });
     }
     else
     {
         _companyServ.AddCompany(_newCompany);
         companies.Add(_newCompany);
         NewCompany = new Company();
         await _currentWindow.ShowMessageAsync("نجاح الإضافة", "تم الإضافة بنجاح", MessageDialogStyle.Affirmative, new MetroDialogSettings()
         {
             AffirmativeButtonText = "موافق",
             DialogMessageFontSize = 25,
             DialogTitleFontSize   = 30
         });
     }
 }