Esempio n. 1
0
        public static ScheduleDE Translate(this ScheduleMD from, ScheduleDE dest = null)
        {
            var to = dest ?? new ScheduleDE();

            if (to.Id <= 0)
            {
                to.Id       = from.Id;
                to.IsActive = true;
            }
            else
            {
                to.IsActive = from.IsActive;
            }
            to.Date        = from.Date;
            to.StartTime   = from.StartTime;
            to.EndTime     = from.EndTime;
            to.AddressLine = from.AddressLine;
            to.City        = from.City;
            to.Province    = from.Province;
            to.Country     = from.Country;
            to.ZipCode     = from.ZipCode;
            to.CreatedDate = from.CreatedDate;
            to.CreatedById = from.CreatedById;
            to.IsValid     = from.IsValid;


            return(to);
        }
Esempio n. 2
0
        public static List <ScheduleMD> Translate(this List <ScheduleDE> list)
        {
            var schedules = new List <ScheduleMD>();

            foreach (var from in list)
            {
                var to = new ScheduleMD();

                to.Id          = from.Id;
                to.Date        = from.Date;
                to.StartTime   = from.StartTime;
                to.EndTime     = from.EndTime;
                to.AddressLine = from.AddressLine;
                to.City        = from.City;
                to.Province    = from.Province;
                to.Country     = from.Country;
                to.ZipCode     = from.ZipCode;
                to.CreatedDate = from.CreatedDate;
                to.CreatedById = from.CreatedById;
                to.IsValid     = from.IsValid;

                schedules.Add(to);
            }
            return(schedules);
        }
Esempio n. 3
0
        public ScheduleMD AddSchedule(ScheduleMD mod)
        {
            try
            {
                var entity = mod.Translate();
                _ScheduleRepo.Insert(entity);
                _ScheduleRepo.CommitAllChanges();
                mod.AddSuccessMessage(string.Format(AppConstants.CRUD_ADD, "Schedule"));
                mod.Id = entity.Id;
            }
            catch (Exception ex)
            {
                mod.AddErrorMessage(string.Format(AppConstants.CRUD_ADD_ERROR, "Schedule"));
            }

            return(mod);
        }
Esempio n. 4
0
        public ScheduleMD ModifySchedule(ScheduleMD mod)
        {
            var entity = mod.Translate();

            try
            {
                _ScheduleRepo.Update(entity);
                _ScheduleRepo.CommitAllChanges();
                mod.AddSuccessMessage(string.Format(AppConstants.CRUD_UPDATE, "Schedule"));
            }
            catch (Exception)
            {
                mod.AddSuccessMessage(string.Format(AppConstants.CRUD_UPDATE_ERROR, "Schedule"));
            }

            return(mod);
        }
Esempio n. 5
0
        public ScheduleMD DeleteSchedule(long id)
        {
            var mod = new ScheduleMD();

            try
            {
                var Schedule = _ScheduleRepo.Fetch(x => x.IsActive);
                Schedule.IsActive = false;
                _ScheduleRepo.Update(Schedule);
                _ScheduleRepo.CommitAllChanges();

                mod.AddSuccessMessage(string.Format(AppConstants.CRUD_DELETE, "Schedule"));
            }
            catch (Exception ex)
            {
                mod.AddErrorMessage(string.Format(AppConstants.CRUD_DELETE_ERROR, "Schedule"));
            }
            return(mod);
        }
Esempio n. 6
0
        public static ScheduleMD Translate(this ScheduleDE from)
        {
            var to = new ScheduleMD();

            to.Id          = from.Id;
            to.Date        = from.Date;
            to.StartTime   = from.StartTime;
            to.EndTime     = from.EndTime;
            to.AddressLine = from.AddressLine;
            to.City        = from.City;
            to.Province    = from.Province;
            to.Country     = from.Country;
            to.ZipCode     = from.ZipCode;
            to.CreatedDate = from.CreatedDate;
            to.CreatedById = from.CreatedById;
            to.IsValid     = from.IsValid;

            return(to);
        }
Esempio n. 7
0
        public async Task <ActionResult> AddSchedule(ScheduleViewModel model)
        {
            //if (model.Gender != Gender.Male || model.Gender != Gender.Female) model.Gender
            if (ModelState.IsValid)
            {
                var eventmd = new EventMD();
                eventmd.Description = model.EventDescription;
                eventmd.EventStatus = EventStatus.Pending;
                var result = _eventService.AddEvent(eventmd);

                if (!result.HasErrors)
                {
                    ScheduleMD schedule = new ScheduleMD();
                    schedule.Date        = model.Date;
                    schedule.StartTime   = model.StartTime;
                    schedule.EndTime     = model.EndTime;
                    schedule.AddressLine = model.AddressLine;
                    schedule.City        = model.City;
                    schedule.Province    = model.Province;
                    schedule.Country     = model.Country;

                    schedule.CreatedDate = DateTime.Now;
                    schedule.CreatedById = Convert.ToInt64(User.Identity.GetUserId());
                    schedule.IsValid     = true;

                    var res = _scheduleService.AddSchedule(schedule);
                    if (res.HasErrors)
                    {
                        model.HasError = true;
                        //model.ErrorMessage.Message = res.ResultMessages.FirstOrDefault().Message;
                        //model.ErrorMessage.MessageType =  "Try again! " + res.ResultMessages.FirstOrDefault().MessageType;
                        //await UserManager.DeleteAsync(user);
                    }

                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View(model));
        }