Пример #1
0
 //Returns true if there was an errand of matching id that was updated.
 public bool UpdateErrand(Errand errand)
 {
     if (errand.ErrandID != 0)            //cannot attempt to update an errand that isnt in the database
     {
         Errand dbErrand = context.Errands.FirstOrDefault(err => errand.ErrandID == err.ErrandID);
         if (dbErrand != null)
         {
             dbErrand.DateOfObservation  = errand.DateOfObservation;
             dbErrand.DepartmentId       = errand.DepartmentId;
             dbErrand.EmployeeId         = errand.EmployeeId;
             dbErrand.InformerName       = errand.InformerName;
             dbErrand.InformerPhone      = errand.InformerPhone;
             dbErrand.InvestigatorAction = errand.InvestigatorAction;
             dbErrand.InvestigatorInfo   = errand.InvestigatorInfo;
             dbErrand.Observation        = errand.Observation;
             dbErrand.Place       = errand.Place;
             dbErrand.RefNumber   = errand.RefNumber;
             dbErrand.StatusId    = errand.StatusId;
             dbErrand.TypeOfCrime = errand.TypeOfCrime;
             context.SaveChanges();
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #2
0
 public string SaveErrand(Errand errand)
 {
     if (errand.ErrandID == 0)            //A new errand not yet added to the database
     {
         errand.RefNumber = CreateErrandRefNumber();
         errand.StatusId  = "S_A";
         context.Errands.Add(errand);
         context.SaveChanges();
     }
     else
     {
         UpdateErrand(errand);
     }
     return(errand.RefNumber);
 }
        public async Task <CrimeContentErrandView> GetCrimeContentErrandView(int errandId)
        {
            Errand viewErrand = await GetErrand(errandId);

            var errandList = from err in Errands
                             join stat in ErrandStatuses on err.StatusId equals stat.StatusId
                             join dep in Departments on err.DepartmentId equals dep.DepartmentId
                             into departmentErrand
                             from deptE in departmentErrand.DefaultIfEmpty()

                             join ee in Employees on err.EmployeeId equals ee.EmployeeId
                             into employeeErrand
                             from empE in employeeErrand.DefaultIfEmpty()

                             orderby err.RefNumber ascending
                             select new CrimeContentErrandView
            {
                DateOfObservation  = err.DateOfObservation,
                ErrandId           = err.ErrandID,
                RefNumber          = err.RefNumber,
                TypeOfCrime        = err.TypeOfCrime,
                StatusName         = stat.StatusName,
                DepartmentName     = (err.DepartmentId == null ? "ej tillsatt" : deptE.DepartmentName),
                EmployeeName       = (err.EmployeeId == null ? "ej tillsatt" : empE.EmployeeName),
                Place              = err.Place,
                Observation        = err.Observation,
                InvestigatorInfo   = err.InvestigatorInfo,
                InvestigatorAction = err.InvestigatorAction,
                InformerName       = err.InformerName,
                InformerPhone      = err.InformerPhone,
                Samples            = err.Samples,
                Pictures           = err.Pictures
            };
            var actualErrand = from crimeContentErrandView in errandList
                               where crimeContentErrandView.ErrandId.Equals(viewErrand.ErrandID)
                               select crimeContentErrandView;

            return(actualErrand.FirstOrDefault());
        }