public async Task <Boolean> Create(Model.Return _return, long userId) { Boolean result = false; try { if (_return != null) { _return.ReferenceNumber = "#" + _return.Order.ReferenceNumberId; _return.CreatedOn = _return.UpdatedOn = DateTime.Now; _return.CreatedById = userId; if (_return.Agent != null && _return.Agent.Id != 0) { _return.AgentId = _return.Agent.Id; } if (_return.Status != null) { _return.StatusId = _return.Status.Id; } if (_return.Order != null && _return.Order.Id != 0) { _return.OrderId = _return.Order.Id; _return.Order.OrderLineItems = null; } if (_return.ReturnLineItems != null) { foreach (var item in _return.ReturnLineItems) { item.CreatedOn = item.UpdatedOn = DateTime.Now; } } if (_return.Notes != null) { foreach (var item in _return.Notes) { item.CreatedOn = item.UpdatedOn = DateTime.Now; item.CreatedById = userId; } } _context.Returns.Update(_return); result = await _context.SaveChangesAsync() > 0; } } catch (Exception ex) { throw new Exception(ex.Message); } return(result); }
public async Task <IActionResult> Update([FromBody] Model.Return _return) { try { var isUpdated = await _coreReturn.Update(_return); if (isUpdated) { return(Ok(_return)); } return(BadRequest()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <Model.Return> Get(long Id) { Model.Return _return = null; try { _return = await _context.Returns .Include(x => x.Agent) .Include(x => x.Order) .Include(x => x.ReturnLineItems) .Include(x => x.Status) .FirstOrDefaultAsync(x => x.Id == Convert.ToInt64(Id)); } catch (Exception ex) { throw new Exception(ex.Message); } return(_return); }
public async Task <IActionResult> Create([FromBody] Model.Return _return) { try { string storeId = User.Claims.First(c => c.Type == "userId").Value; // Get stored user id when user sign in or sign up if (!string.IsNullOrEmpty(storeId)) { var userId = Convert.ToInt64(storeId); var isCreated = await _coreReturn.Create(_return, userId); if (isCreated) { return(Created("", _return));// return created status 200 when request is successfull; } } return(BadRequest()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }