Esempio n. 1
0
 public JournalDriverModel(JournalDriver item, Driver driver)
 {
     JournalId     = item.JournalId;
     DriverId      = item.UserId;
     Description   = item.Description;
     Status        = (int)item.Status;
     CreatedTS     = item.CreatedTS;
     LastUpdatedTS = item.LastUpdatedTS;
     if (driver != null)
     {
         Driver = new DriverModel(driver);
     }
 }
Esempio n. 2
0
        public GetJournalDriverResponse AddJournalDriver(ServiceRequest request)
        {
            return(Run <ServiceRequest, GetJournalDriverResponse>(request, (resp, db, session) =>
            {
                long journalId = GetParam(request.JournalId);
                long driverId = GetParam(request.DriverId);

                int?status = request.Status;
                string description = request.Description;

                if (!db.DBModel.Journals.Any(x => x.Id == journalId && x.Status != JournalStatus.Deleted))
                {
                    throw new KException("Journal Not found");
                }

                var driver = db.DBModel.Drivers.FirstOrDefault(x => x.Id == driverId && x.Status != Status.Deleted);
                if (driver == null)
                {
                    throw new KException("Driver Not found");
                }

                JournalDriver item = db.DBModel.JournalDrivers.FirstOrDefault(x => x.JournalId == journalId && x.UserId == driverId);
                if (item == null)
                {
                    item = new JournalDriver();
                    item.JournalId = journalId;
                    item.Description = description;
                    item.UserId = driverId;
                    item.CreatedTS = DateTime.Now;
                    item.LastUpdatedTS = DateTime.Now;
                    item.Status = JournalDriverStatus.Actived;

                    db.DBModel.JournalDrivers.Add(item);
                }
                else
                {
                    item.Description = description;
                    item.LastUpdatedTS = DateTime.Now;
                }
                db.SaveChanges();
                resp.Item = new JournalDriverModel(item, driver);
            }, false));
        }