public IHttpActionResult RegisterService(Int32?localid, ServiceEntities model) { try { using (var ts = new TransactionScope()) { if (model == null) { response.Data = null; response.Error = true; response.Message = "Error, Empty model"; return(Content(HttpStatusCode.BadRequest, response)); } else { Service service = new Service(); if (!localid.HasValue) { response.Data = null; response.Error = true; response.Message = "Error, local empty"; return(Content(HttpStatusCode.BadRequest, response)); } else { context.Service.Add(service); service.Name = model.Name; service.Detail = model.Detail; service.LocalId = localid; service.UrlPhoto = model.UrlPhoto; service.Cost = model.Cost; service.Status = ConstantHelpers.Status.ACTIVE; context.SaveChanges(); response.Data = null; response.Error = false; response.Message = "Success, saved service"; } ts.Complete(); } } return(Ok(response)); } catch (Exception ex) { return(Unauthorized()); } }
public IHttpActionResult UpdateService(Int32?localid, ServiceEntities model) { try { using (var ts = new TransactionScope()) { if (model == null) { response.Data = null; response.Error = true; response.Message = "Error, Empty model"; return(Content(HttpStatusCode.BadRequest, response)); } else { Service service = new Service(); if (model.ServiceId.HasValue && localid.HasValue) { service = context.Service.FirstOrDefault(x => x.LocalId == localid && x.ServiceId == model.ServiceId); service.Name = model.Name; service.Detail = model.Detail; service.LocalId = localid; service.UrlPhoto = model.UrlPhoto; service.Cost = model.Cost; context.SaveChanges(); response.Data = null; response.Error = false; response.Message = "Success, updated service"; } else { response.Data = null; response.Error = true; response.Message = "Error, Local or provider id empty"; } ts.Complete(); } } return(Ok(response)); } catch (Exception ex) { return(Unauthorized()); } }