public IHttpActionResult Create(UserDepartmentCreatePrm userDepartmentCreatePrm) { try { this.UserDepartmentWrapper.Create(userDepartmentCreatePrm); // return the response return(Ok(new GeneralResponse() { Error = false, Message = "" })); } catch (ManagerException mex) { // Save entry in log this.SystemLogWrapper.Register(SERVER, this.GetUserDataId(), SystemLogWrapper.TYPE_WARNING, mex); // Throw the exception return(Ok(new GeneralResponse() { Error = true, Message = mex.Message })); } catch (WrapperException wex) { // Save entry in log this.SystemLogWrapper.Register(SERVER, this.GetUserDataId(), SystemLogWrapper.TYPE_WARNING, wex); // Throw the exception return(Ok(new GeneralResponse() { Error = true, Message = wex.Message })); } catch (System.Exception ex) { // Save entry in log this.SystemLogWrapper.Register(SERVER, this.GetUserDataId(), SystemLogWrapper.TYPE_ERROR, ex); // Throw the exception throw ExceptionResponse.ThrowException("Error creating user department", ERROR_CREATING_USER_DEPARTMENT); } }
/// <summary> /// Name: Create /// Description: Method to create user department /// </summary> /// <param name="userDepartmentCreatePrm">UserDepartmentCreatePrm</param> public void Create(UserDepartmentCreatePrm userDepartmentCreatePrm) { // Open trasaction param using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { // Get deparments from usr IEnumerable <UserDepartment> collectionUserDepartment = this.IUserDepartmentMgr.GetByUserIdEventId(userDepartmentCreatePrm.UserId, userDepartmentCreatePrm.EventId); Dictionary <Guid, UserDepartment> dicUserDeparmtent = new Dictionary <Guid, UserDepartment>(); foreach (UserDepartment userDepartment in collectionUserDepartment) { dicUserDeparmtent.Add(userDepartment.DepartmentId, userDepartment); } // Check if are not repeated foreach (Guid departmentId in userDepartmentCreatePrm.CollectionDepartmentId) { if (dicUserDeparmtent.ContainsKey(departmentId)) { throw new WrapperException(ERROR_RELATION_ALREADY_EXIST, new System.Exception("User Department Relation already exist")); } } // Create collection of element ICollection <UserDepartment> collectionUserDepartmentToCreate = new List <UserDepartment>(); foreach (Guid departmentId in userDepartmentCreatePrm.CollectionDepartmentId) { collectionUserDepartmentToCreate.Add(new UserDepartment() { UserId = userDepartmentCreatePrm.UserId, DepartmentId = departmentId }); } // Save the collection this.IUserDepartmentMgr.Save(collectionUserDepartmentToCreate); // Scope complete scope.Complete(); } }