public int DeleteById(int id) { Company company; CompanyModel model = this.CompanyModel; if ((company = model.GetOneById(id).Value) == null) { var error = new Error( Errors.CODE_ERRORTYPE_INVALID_OBJECT, ErrorsTexts.GetResultError_Subject, ErrorsTexts.GetResultError_NotFound); this.LogError("Company.DeleteById", error); throw new FaultException <Error>(error, error.errorMessage); } if (company.PrimaryContact != null) { company.PrimaryContact = null; model.RegisterSave(company, true); } var userModel = this.UserModel; foreach (var user in company.Users) { userModel.RealDelete(user, true); } model.Refresh(ref company); model.RegisterDelete(company, true); //IoC.Resolve<RealTimeNotificationModel>().NotifyClientsAboutChangesInTable<Company>(NotificationType.Delete, company.Id, company.Id); return(id); }
/// <summary> /// Initializes a new instance of the <see cref="ImportUsersViewModelValidator"/> class. /// </summary> /// <param name="companyModel"> /// The company Model. /// </param> public ImportUsersViewModelValidator(CompanyModel companyModel) { this.RuleFor(x => x.ProfilesFile).NotEmpty().WithMessage("File is null or empty"); this.RuleFor(x => x.CompanyId) .NotEmpty() .WithMessage("Company is empty") .Must(x => companyModel.GetOneById(x).Value != null) .WithMessage("Company doesn't exist"); }
/// <summary> /// Initializes a new instance of the <see cref="CompanyThemeDTOValidator"/> class. /// </summary> /// <param name="companyModel"> /// The company Model. /// </param> public CompanyThemeDTOValidator(CompanyModel companyModel) { Company company = null; this.RuleFor(model => model.companyId) .Cascade(CascadeMode.StopOnFirstFailure) .NotEmpty() .WithError(Errors.CODE_ERRORTYPE_INVALID_OBJECT, "Company is empty") .Must(x => (company = companyModel.GetOneById(x).Value) != null) .WithError(Errors.CODE_ERRORTYPE_INVALID_OBJECT, "Company doesn't exist") .Must(x => (company.CurrentLicense ?? company.FutureActiveLicense).With(cl => cl.LicenseStatus == CompanyLicenseStatus.Enterprise)) .WithError(Errors.CODE_ERRORTYPE_INVALID_OBJECT, "Company is not enterprise"); }