Exemplo n.º 1
0
        public void AddOrUpdateServiceRequest(ServiceRequestDTO serviceRequest)
        {
            DateTime timestamp = DateTime.Parse(DateTime.Now.ToString("O"));
            var      request   = new ServiceRequest.DataAccess.ServiceRequest
            {
                ID               = serviceRequest.ID != Guid.Empty ? serviceRequest.ID : Guid.NewGuid(),
                Description      = serviceRequest.Description,
                BuildingCode     = serviceRequest.BuildingCode,
                CurrentStatus    = (DataAccess.CurrentStatus?)serviceRequest.CurrentStatus,
                LastModifiedBy   = serviceRequest.LastModifiedBy,
                LastModifiedDate = timestamp
            };

            //hmm need to check if it is a new request or existing one and then proceed with updating/adding
            if (serviceRequest.ID != Guid.Empty) //exists => update
            {
                _repo.UpdateServiceRequest(request);
            }
            else
            {
                request.CreatedBy   = serviceRequest.LastModifiedBy;
                request.CreatedDate = timestamp;
                _repo.AddServiceRequest(request);
            }
        }
 public void AddServiceRequest(ServiceRequest newRequest)
 {
     DbContext.serviceRequests.Add(newRequest);
     DbContext.SaveChanges();
 }