public async Task <IActionResult> BefriendUser(int id, int friendId) { if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var friend = await _repository.GetFriend(id, friendId); if (friend != null) { return(BadRequest("User is already a friend.")); } if (await _repository.GetUser(friendId, false) == null) { return(NotFound()); } friend = new Friend { FrienderId = id, FriendeeId = friendId }; _repository.Add(friend); if (await _repository.SaveAll()) { return(Ok()); } return(BadRequest("Failed to add a friend")); }
public IHttpActionResult Add(NetworkModel networkModel) { if (networkModel == null) { var errorMessage = _messages.GetMessage(Generic.NullObject); return(BadRequest(errorMessage)); } if (_networkRep.GetAll() .Any(p => p.Name == networkModel.Name)) { var errorMessage = _messages.GetMessage(Custom.Conflict, "Network", "Name"); return(Conflict(errorMessage)); } _credentials.SetCredentials(Request.Headers.Authorization.Parameter); var userId = _userRep.Get(_credentials.Email, _credentials.Password).Id; var newNetwork = _mapper.Map <Network>(networkModel); newNetwork.User_Id = userId; newNetwork.Address = _guid.GetAddress(); newNetwork.ProductionDate = _dateTime.GetDateTime(); _networkRep.Add(newNetwork); var createdNetwork = _mapper.Map <NetworkModelGet>(newNetwork); return(CreatedAtRoute("GetNetwork", new { id = createdNetwork.Id }, createdNetwork)); }
public void Add(Network network) { _networks.Add(network); }
public GeneralResponse AddNetwork(AddNetworkRequestOld request) { GeneralResponse response = new GeneralResponse(); try { Network network = new Network(); network.ID = Guid.NewGuid(); network.CreateDate = PersianDateTime.Now; network.CreateEmployee = _employeeRepository.FindBy(request.CreateEmployeeID); network.DeliverWhenCreditLow = request.DeliverWhenCreditLow; network.NetworkName = request.NetworkName; network.Note = request.Note; network.RowVersion = 1; // Validation if (network.GetBrokenRules().Count() > 0) { foreach (BusinessRule businessRule in network.GetBrokenRules()) { response.ErrorMessages.Add(businessRule.Rule); } return(response); } // be jaye Triggere After Insert. NetworkCenter-ha insert mishavad IList <NetworkCenter> networkCenters = new List <NetworkCenter>(); foreach (Center center in _centerRepository.FindAll()) { NetworkCenter networkCenter = new NetworkCenter(); networkCenter.Network = network; networkCenter.Center = center; networkCenter.CreateDate = PersianDateTime.Now; networkCenter.CreateEmployee = network.CreateEmployee; networkCenter.Status = NetworkCenterStatus.NotDefined; networkCenter.RowVersion = 1; networkCenters.Add(networkCenter); } network.NetworkCenters = networkCenters; _networkRepository.Add(network); _uow.Commit(); ////response.success = true; } catch (Exception ex) { response.ErrorMessages.Add(ex.Message); if (ex.InnerException != null) { response.ErrorMessages.Add("FIRST INNER EXPCEPTION: " + ex.InnerException.Message); if (ex.InnerException.InnerException != null) { response.ErrorMessages.Add("SECOND INNER EXPCEPTION: " + ex.InnerException.InnerException.Message); } } } return(response); }