Example #1
0
        public string Update(AircraftViewModel model)
        {
            string msg = string.Empty;

            try
            {
                AircraftType aircraft = _context.AsQueryable <AircraftType>().Where(x => x.ID == model.ID).FirstOrDefault();
                bool         isExists = false;

                #region Check if new name changed
                if (aircraft.Name.Trim().ToUpper() != model.Name.Trim().ToUpper())
                {
                    int ctr = _context.AsQueryable <AircraftType>().Where(x => x.Name.Trim() == model.Name.Trim()).Count();
                    if (ctr > 0)
                    {
                        isExists = true;
                    }
                }
                #endregion

                if (isExists)
                {
                    msg = "Aircraft name already exists.";
                }
                else
                {
                    if (!string.IsNullOrEmpty(model.Name))
                    {
                        aircraft.Name = model.Name;
                    }
                    if (!string.IsNullOrEmpty(model.Description))
                    {
                        aircraft.Description = model.Description;
                    }
                    aircraft.DateModified = DateTime.Now;

                    if (aircraft != null)
                    {
                        _context.Update <AircraftType>(aircraft);
                        _context.SaveChanges();
                    }
                    msg = "Aircraft updated.";
                }
            }
            catch (Exception ex)
            {
                LogsViewModel error = new LogsViewModel()
                {
                    ActionType   = ActionType.Error.ToString(),
                    Description  = ex.Message + "\n" + ex.StackTrace,
                    ModifiedBy   = "Aircraft Service Error : Update()",
                    DateModified = DateTime.Now.ToString("MM/dd/yyyy HH:mm")
                };
                new LogsService().Create(error);
                msg = "Unexpected error encountered. Please contact your system administrator.";
                //log error
            }
            return(msg);
        }
Example #2
0
        public string Update(CalendarViewModel model)
        {
            string msg = string.Empty;

            try
            {
                #region Update Calendar Schedule
                var calendar = _context.AsQueryable <Schedule>().Where(x => x.ID == model.ID).FirstOrDefault();
                if (calendar != null)
                {
                    if (model.IsChangeSchedOnly == false)
                    {
                        if (!string.IsNullOrEmpty(model.Title))
                        {
                            calendar.Name = model.Title;
                        }
                        if (model.AircraftID > 0)
                        {
                            calendar.AircraftID = model.AircraftID;
                        }
                        if (model.RegistrationID > 0)
                        {
                            calendar.RegistrationID = model.RegistrationID;
                        }
                        if (!string.IsNullOrEmpty(model.Start))
                        {
                            calendar.StartDate = DateTime.Parse(model.Start);
                        }
                        if (!string.IsNullOrEmpty(model.End))
                        {
                            calendar.EndDate = DateTime.Parse(model.End);
                        }
                        if (model.RouteStartID > 0)
                        {
                            calendar.RouteStartID = model.RouteStartID;
                        }
                        if (model.DestinationID > 0)
                        {
                            calendar.RouteDestinationID = model.DestinationID;
                        }
                        if (model.RouteEndID > 0)
                        {
                            calendar.RouteEndID = model.RouteEndID;
                        }
                        if (model.PilotID > 0)
                        {
                            calendar.PilotID = model.PilotID;
                        }
                        if (model.CopilotID > 0)
                        {
                            calendar.AssistantPilotID = model.CopilotID;
                        }
                        if (!string.IsNullOrEmpty(model.Notes))
                        {
                            calendar.Notes = model.Notes;
                        }
                        if (!string.IsNullOrEmpty(model.Passengers))
                        {
                            calendar.Passengers = model.Passengers;
                        }
                        if (!string.IsNullOrEmpty(model.FlightInfo))
                        {
                            calendar.FlightInfo = model.FlightInfo;
                        }
                        if (!string.IsNullOrEmpty(model.TechnicalStops))
                        {
                            calendar.TechnicalStops = model.TechnicalStops;
                        }
                        if (!string.IsNullOrEmpty(model.ETC))
                        {
                            calendar.ETC = model.ETC;
                        }
                        if (!string.IsNullOrEmpty(model.WaitingStart))
                        {
                            calendar.WaitingStart = DateTime.Parse(model.WaitingStart);
                        }
                        if (!string.IsNullOrEmpty(model.WaitingEnd))
                        {
                            calendar.WaitingEnd = DateTime.Parse(model.WaitingEnd);
                        }

                        _context.Update(calendar);
                        _context.SaveChanges();

                        #region Update Crew
                        //delete crew first
                        this.DeleteCrewBySchedule(calendar.ID, model.LoggedUserID);
                        string   crewids = model.CrewIDs.Remove(model.CrewIDs.Length - 1);
                        string[] ids     = crewids.Split(',');
                        foreach (var crewid in ids)
                        {
                            if (!string.IsNullOrEmpty(crewid))
                            {
                                CrewViewModel crewmodel = new CrewViewModel()
                                {
                                    CrewID     = Convert.ToInt32(crewid),
                                    ScheduleID = calendar.ID
                                };
                                this.CreateCrews(crewmodel);
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        //change sched only
                        string newStart = "", newEnd = "", updatedEnd = "", newStart2 = "", updatedStart2 = "", newEnd2 = "", updatedEnd2 = "";

                        newStart  = DateTime.Parse(model.Start).ToString("yyyy-MM-dd HH:mm");
                        newEnd    = DateTime.Parse(calendar.EndDate.ToString()).ToString("yyyy-MM-dd HH:mm");
                        newStart2 = DateTime.Parse(calendar.WaitingStart.ToString()).ToString("yyyy-MM-dd HH:mm");
                        newEnd2   = DateTime.Parse(calendar.WaitingEnd.ToString()).ToString("yyyy-MM-dd HH:mm");

                        #region Get diffrence
                        double diff1 = 0;
                        diff1 = calendar.StartDate.Date.Subtract(calendar.EndDate).Days;
                        //((DateTime)calendar.WaitingEnd).Date.Subtract( calendar.StartDate.Date ).Days;
                        #endregion

                        if (diff1 > 0)
                        {
                            updatedEnd = DateTime.Parse(newStart).AddDays(diff1).ToString("yyyy-MM-dd HH:mm").Substring(0, 10) + newEnd.Substring(10);
                        }
                        else
                        {
                            updatedEnd = newStart.Substring(0, 10) + newEnd.Substring(10);
                        }

                        updatedStart2 = newStart.Substring(0, 10) + newStart2.Substring(10);
                        updatedEnd2   = newEnd2.Substring(0, 10) + newEnd2.Substring(10);

                        calendar.StartDate    = DateTime.Parse(model.Start);
                        calendar.EndDate      = DateTime.Parse(updatedEnd);
                        calendar.WaitingStart = DateTime.Parse(updatedStart2);
                        calendar.WaitingEnd   = DateTime.Parse(updatedEnd2);

                        _context.Update(calendar);
                        _context.SaveChanges();
                    }

                    msg = "Schedule updated.";
                }
                #endregion

                #region Log Create
                string fullname = string.Empty;
                var    user     = _userService.GetAll().Where(x => x.ID == model.LoggedUserID).FirstOrDefault();
                if (user != null)
                {
                    fullname = string.Format("{0}, {1}", user.LastName, user.FirstName);
                    LogsViewModel log = new LogsViewModel()
                    {
                        ActionType   = ActionType.DataModification.ToString(),
                        Description  = string.Format("Schedule Updated. <br /> ScheduleID:{0} <br /> LoggedUserID: {1}", model.ID, user.ID),
                        ModifiedBy   = fullname,
                        DateModified = DateTime.Now.ToString("MM/dd/yyyy HH:mm")
                    };
                    new LogsService().Create(log);
                }
                #endregion
            }
            catch (Exception ex)
            {
                LogsViewModel error = new LogsViewModel()
                {
                    ActionType   = ActionType.Error.ToString(),
                    Description  = ex.Message + "\n" + ex.StackTrace,
                    ModifiedBy   = "Calendar Service Error : Update()",
                    DateModified = DateTime.Now.ToString("MM/dd/yyyy HH:mm")
                };
                new LogsService().Create(error);
                msg = "Unexpected error encountered. Please contact your system administrator.";
            }

            return(msg);
        }
Example #3
0
        public string Update(UserViewModel model)
        {
            string msg = string.Empty;

            try
            {
                User user     = _context.AsQueryable <User>().Where(x => x.ID == model.ID).FirstOrDefault();
                bool isExists = false;
                #region  check if current username and email is not equal to new value
                isExists = this.IsExists(user.ID, user.Username, model.Username, user.Email, model.Email);
                #endregion

                if (isExists)
                {
                    msg = "Your profile email or username already exists.";
                }
                else
                {
                    if (!string.IsNullOrEmpty(model.Password))
                    {
                        user.Password = ThreeDES.Encrypt(model.Password);
                    }
                    if (!string.IsNullOrEmpty(model.Username))
                    {
                        user.Username = model.Username;
                    }
                    if (!string.IsNullOrEmpty(model.FirstName))
                    {
                        user.FirstName = model.FirstName;
                    }
                    if (!string.IsNullOrEmpty(model.LastName))
                    {
                        user.LastName = model.LastName;
                    }
                    if (!string.IsNullOrEmpty(model.MiddleName))
                    {
                        user.MiddleName = model.MiddleName;
                    }
                    if (!string.IsNullOrEmpty(model.Address))
                    {
                        user.Address = model.Address;
                    }
                    if (!string.IsNullOrEmpty(model.Phone))
                    {
                        user.Phone = model.Phone;
                    }
                    if (!string.IsNullOrEmpty(model.Email))
                    {
                        user.Email = model.Email;
                    }
                    if (!string.IsNullOrEmpty(model.SSS))
                    {
                        user.SSS = model.SSS;
                    }
                    if (!string.IsNullOrEmpty(model.TIN))
                    {
                        user.TIN = model.TIN;
                    }
                    if (model.RoleID != 0)
                    {
                        user.RoleID = model.RoleID;
                    }
                    user.DateModified = DateTime.Now;

                    if (user != null)
                    {
                        _context.Update <User>(user);
                        _context.SaveChanges();
                    }
                    msg = "Profile updated.";
                }
            }
            catch (Exception ex)
            {
                msg = "Unexpected error encountered. Please contact your system administrator.";
                LogsViewModel error = new LogsViewModel()
                {
                    ActionType   = ActionType.Error.ToString(),
                    Description  = ex.Message + "\n" + ex.StackTrace,
                    ModifiedBy   = "User Service Error : Update()",
                    DateModified = DateTime.Now.ToString("MM/dd/yyyy HH:mm")
                };
                new LogsService().Create(error);
            }
            return(msg);
        }