Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "CategoryName")] tb_Categories tb_Categories)
        {
            if (ModelState.IsValid)
            {
                db.tb_Categories.Add(tb_Categories);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tb_Categories));
        }
        public ActionResult AddSchedule(SemesterTaughtModel model, int?Campus, int?Building, int?Blding, FormCollection formCollection)
        {
            //var semesterRecID = db.tb_Semesters.Where(t => t.DateFrom >= DateTime.UtcNow && t.DateTo < DateTime.UtcNow).FirstOrDefault().SemesterRecID;
            bool scheduleStatus = false;

            if (model._ScheduleStatusID == 1)
            {
                scheduleStatus = true;
            }

            int semesterRecID = 0;

            try
            {
                // >>check here
                semesterRecID = db.tb_Semesters.Where(t => t.SemesterYear == DateTime.UtcNow.Year.ToString())
                                .Where(t => t.SemesterStartDate <= DateTime.UtcNow)
                                .Where(t => t.SemesterEndDate > DateTime.UtcNow).FirstOrDefault().SemesterID;
            }
            catch (Exception)
            {
                // not good here. situation when DateTime.UtcNow isn't in semester period. taking next semester then
                // >>check here
                semesterRecID = db.tb_Semesters.Where(t => t.SemesterStartDate > DateTime.UtcNow).FirstOrDefault().SemesterID;
            }

            tb_SemesterTaught newSemesterTaught = new tb_SemesterTaught()
            {
                SemesterRecID  = semesterRecID,
                MemberID       = model._MemberID,
                BuildingID     = Building ?? 0, //not present on the Knock page
                Room           = model._Room ?? " ",
                Class          = model._Class ?? " ",
                ClassStart     = model._StartTime.TimeOfDay,
                ClassEnd       = model._EndTime.TimeOfDay,
                ClassWeekDayID = model._ClassWeekDayID,
                ScheduleStatus = scheduleStatus
            };

            ////if (oldAssessment == null)
            ////{
            ////    db.tb_Assessment.Add(AssessActivity._Assessment);
            ////}

            if (ModelState.IsValid)
            {
                db.tb_SemesterTaught.Add(newSemesterTaught);
                db.SaveChanges();
                return(RedirectToAction("Details", "Home", new { @id = model._MemberID }));
            }

            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult CampusesMapping([Bind(Include = "ID,ScheduleMappingName")] tb_CampusMapping tb_CampusMapping, int?CampusId)
        {
            if (CampusId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            using (LRCEntities context = new LRCEntities())
            {
                tb_CampusMapping campusMapping = new tb_CampusMapping
                {
                    CampusID            = CampusId ?? 0,
                    ScheduleMappingName = tb_CampusMapping.ScheduleMappingName
                };
                context.tb_CampusMapping.Add(campusMapping);
                try
                {
                    context.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                }
            }
            ViewBag.Campuses = db.tb_CampusMapping.Include(c => c.tb_Campus).Where(m => m.ScheduleMappingName != null).ToList();
            var campusNames = new SelectList(db.tb_Campus, "CampusID", "CampusName");

            ViewBag.CampusId = campusNames.OrderBy(t => t.Text);
            return(View());
        }
Exemplo n.º 4
0
        public ActionResult ScheduleMapping([Bind(Include = "ID,ColumnNameCBU")] tb_ScheduleImportMapping tb_ScheduleImportMapping, int?ID)
        {
            if (ID == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            using (LRCEntities context = new LRCEntities())
            {
                try
                {
                    var rec = db.tb_ScheduleImportMapping.Find(ID);
                    rec.ColumnNameCBU = tb_ScheduleImportMapping.ColumnNameCBU;
                    context.tb_ScheduleImportMapping.Attach(rec);
                    context.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                }
            }
            ViewBag.Columns = db.tb_ScheduleImportMapping.ToList();
            var modelFields = new SelectList(db.tb_ScheduleImportMapping, "ID", "ModelCorrespondingField");

            ViewBag.ID = modelFields;
            return(View());
        }
Exemplo n.º 5
0
        }                                                          //for Chosen Plugin DDL

        public List <string> AddEditActivity(int memberId, int activityID, int activityStatusID, bool?isParticipated, DateTime activityDate, string activityNote, string userId)
        {
            Error error = new Error();

            error.errCode = ErrorDetail.Success;
            List <string> errs     = new List <string>();
            List <string> warnings = new List <string>();
            string        warning  = String.Empty;

            using (LRCEntities context = new LRCEntities())
            {
                try
                {
                    var existingActivity = context.tb_MemberActivity.Where(t => t.MemberID == memberId && t.ActivityID == activityID).FirstOrDefault();
                    if (existingActivity == null) // Add new activity for selected Member
                    {
                        tb_MemberActivity memberActivity = new tb_MemberActivity
                        {
                            ActivityID       = activityID,
                            MemberID         = memberId,
                            ActivityStatusID = activityStatusID,
                            Participated     = isParticipated
                        };
                        context.tb_MemberActivity.Add(memberActivity);
                    }
                    else //Edit existing activity for selected Member
                    {
                        existingActivity.ActivityStatusID = activityStatusID;
                        existingActivity.Participated     = isParticipated;
                    }

                    tb_Activity activity = context.tb_Activity.Find(activityID);
                    // Change if Activity was edited (activityDate or ActivityNote fields)
                    if (activity.ActivityDate != activityDate || activity.ActivityNote.ToUpper() != activityNote.ToUpper())
                    {
                        activity.ModifiedBy       = userId;
                        activity.ModifiedDateTime = DateTime.UtcNow;
                        activity.ActivityDate     = activityDate;
                        activity.ActivityNote     = activityNote;
                    }
                    context.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    error.errCode = ErrorDetail.DataImportError;
                    error.errMsg  = ErrorDetail.GetMsg(error.errCode);
                    foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
                    {
                        error.errMsg += ". Object: " + validationError.Entry.Entity.ToString();
                        foreach (DbValidationError err in validationError.ValidationErrors)
                        {
                            error.errMsg += ". " + err.ErrorMessage;
                        }
                    }
                    errs.Add("Error #" + error.errCode.ToString() + "!" + error.errMsg);
                    return(errs);
                }
            }
            return(errs);
        }
Exemplo n.º 6
0
        public ActionResult AddNote([Bind(Include = "_MemberID,_Note,_NoteDate,_NoteTypeID,_TakenBy")] AddNoteModel model)
        {
            Error error = new Error();

            error.errCode = ErrorDetail.Success;
            error.errMsg  = ErrorDetail.GetMsg(error.errCode);
            List <string> errs = new List <string>();

            try
            {
                tb_MemberNotes memberNote = new tb_MemberNotes()
                {
                    MemberID      = model._MemberID,
                    Notes         = model._Note,
                    NoteDate      = model._NoteDate,
                    NoteTypeID    = model._NoteTypeID,
                    TakenBy       = model._TakenBy,
                    AddedDateTime = DateTime.UtcNow
                };
                db.tb_MemberNotes.Add(memberNote);

                model._NoteTypes = new SelectList(db.tb_NoteType, "NoteTypeID", "NoteType");
                ViewBag._TakenBy = new SelectList(db.AspNetUsers.OrderBy(s => s.LastFirstName), "Id", "LastFirstName");
                tb_MemberMaster fm = db.tb_MemberMaster.Find(model._MemberID);
                ViewBag.MemberName = fm.FirstName + " " + fm.LastName;
                model._MemberNotes = db.tb_MemberNotes.Where(t => t.MemberID == model._MemberID).ToList(); //before
                db.SaveChanges();
                model._MemberNotes = db.tb_MemberNotes.Where(t => t.MemberID == model._MemberID).ToList(); //after
            }
            catch (Exception ex)
            {
                error.errCode = ErrorDetail.DataImportError;
                error.errMsg  = ErrorDetail.GetMsg(error.errCode);
                errs.Add("Error #" + error.errCode.ToString() + "!" + error.errMsg + ". " + ex.Message);
                ViewData["ErrorList"] = errs;
                return(View(model));
            }

            return(View(model));
        }
Exemplo n.º 7
0
        //Check if current AreaName is present in tb_Area already and add it if not
        public static List <string> GetAreaID(string AreaName, out int areaID)
        {
            areaID = 0;
            Error error = new Error();

            error.errCode = ErrorDetail.Success;
            error.errMsg  = ErrorDetail.GetMsg(error.errCode);
            List <string> errs    = new List <string>();
            tb_Area       tb_area = new tb_Area();

            using (LRCEntities context = new LRCEntities())
            {
                var areas = context.tb_Area.Where(t => t.AreaName.ToUpper() == AreaName.ToUpper());
                if (areas.Count() == 0)
                {
                    tb_area.AreaName = AreaName;
                    tb_area.AreaDesc = String.Empty; //??? may be add it later with some Edit Area Form
                    context.tb_Area.Add(tb_area);
                    try
                    {
                        context.SaveChanges();
                        areaID = tb_area.AreaID; // new AreaID of added Area
                    }
                    catch (DbEntityValidationException ex)
                    {
                        error.errCode = ErrorDetail.DataImportError;
                        error.errMsg  = ErrorDetail.GetMsg(error.errCode);
                        foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
                        {
                            error.errMsg += ". Object: " + validationError.Entry.Entity.ToString();
                            foreach (DbValidationError err in validationError.ValidationErrors)
                            {
                                error.errMsg += ". " + err.ErrorMessage;
                            }
                        }
                        errs.Add("Error #" + error.errCode.ToString() + "!" + error.errMsg);
                        return(errs);
                    }
                }
                else
                {
                    //return AreaID of founded Area
                    areaID = areas.FirstOrDefault().AreaID;
                }
            }
            return(errs);
        }
Exemplo n.º 8
0
 public ActionResult RemoveScheduleCampusMapping(int?Id)
 {
     if (Id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     using (LRCEntities context = new LRCEntities())
     {
         var rec = context.tb_CampusMapping.Find(Id);
         context.tb_CampusMapping.Remove(rec);
         try
         {
             context.SaveChanges();
         }
         catch (DbEntityValidationException ex)
         {
         }
     }
     return(RedirectToAction("CampusesMapping"));
 }
Exemplo n.º 9
0
 public ActionResult DeleteScheduleRecord(int?errId)
 {
     if (errId == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     using (LRCEntities context = new LRCEntities())
     {
         var me = context.tb_Schedule_Error.Find(errId);
         context.tb_Schedule_Error.Remove(me);
         try
         {
             context.SaveChanges();
         }
         catch (DbEntityValidationException ex)
         {
         }
     }
     return(RedirectToAction("ScheduleImportErrors"));
 }
Exemplo n.º 10
0
        public ActionResult CreateMemberRoles(CreateRoleModel model)
        {
            if (ModelState.IsValid)
            {
                tb_MemberRoles role = new tb_MemberRoles();
                role.MemberID  = model._MemberID;
                role.RoleID    = model._RoleID;
                role.BodyID    = model._BodyID;
                role.StartDate = model._StartDate;
                role.EndDate   = model._EndDate;

                db.tb_MemberRoles.Add(role);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Exemplo n.º 11
0
        public ActionResult DeleteActivity(int?ActivityID, int?MemberId, int?CollegeID)
        {
            Error error = new Error();

            error.errCode = ErrorDetail.Success;
            if (ActivityID == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            using (LRCEntities context = new LRCEntities())
            {
                try
                {
                    tb_MemberActivity activity = context.tb_MemberActivity.Find(ActivityID);
                    if (activity == null)
                    {
                        return(HttpNotFound());
                    }
                    context.tb_MemberActivity.Remove(activity);
                    context.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    error.errCode = ErrorDetail.DataImportError;
                    error.errMsg  = ErrorDetail.GetMsg(error.errCode);
                    foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
                    {
                        error.errMsg += ". Object: " + validationError.Entry.Entity.ToString();
                        foreach (DbValidationError err in validationError.ValidationErrors)
                        {
                            error.errMsg += ". " + err.ErrorMessage;
                        }
                    }
                }
            }
            return(RedirectToAction("AddPersonAssessmentActivity", new { @id = MemberId, CollegeID = CollegeID }));
        }
Exemplo n.º 12
0
        public ActionResult AddBuilding(HttpPostedFileBase file, [Bind(Include = "_CollegeID,_CampusID,_BuildingName")] AddBuildingModel model)
        {
            Error error = new Error();

            error.errCode = ErrorDetail.Success;
            error.errMsg  = ErrorDetail.GetMsg(error.errCode);
            List <string> errs = new List <string>();

            model._Colleges = new List <SelectListItem>
            {
                new SelectListItem()
                {
                    Value = "0", Text = "-- Select One --"
                }
            }.Concat(db.tb_College.Select(x => new SelectListItem
            {
                Value = x.CollegeID.ToString(), Text = x.CollegeName
            }));
            model._Campuses   = new SelectList(db.tb_Campus.OrderBy(s => s.CampusName), "CampusID", "CampusName", model._CampusID);
            model._tb_College = db.tb_College;

            if (file != null && file.ContentLength > 0)
            {
                try
                {
                    var extension = file.FileName.Split('.').Last().ToUpper();
                    if (extension != "PDF" && extension != "JPG")
                    {
                        ViewBag.Message = "Selected file type is not PDF or JPEG";
                        return(View(model));
                    }

                    string path = Path.Combine(Server.MapPath(MvcApplication.BuildingsFolder), file.FileName);
                    file.SaveAs(path);
                    ViewBag.Message = "File uploaded successfully";
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "ERROR:" + ex.Message.ToString();
                }
            }
            else
            {
                ViewBag.Message = "You have not specified a file.";

                return(View(model));
            }

            var buildings = db.tb_Building.Where(s => s.BuildingName.ToUpper() == model._BuildingName.ToUpper());

            //Check dublicates
            if (buildings.ToList().Count == 0)
            {
                tb_Building building = new tb_Building()
                {
                    CampusID     = model._CampusID,
                    BuildingName = model._BuildingName,
                    ImagePath    = file.FileName
                };
                db.tb_Building.Add(building);
            }
            else
            {
                tb_Building building = buildings.FirstOrDefault();
                building.CampusID     = model._CampusID;
                building.BuildingName = model._BuildingName;
                building.ImagePath    = file.FileName;
                db.tb_Building.Attach(building);
            }
            try
            {
                db.SaveChanges();
                model._tb_College = db.tb_College;
            }
            catch (Exception ex)
            {
                error.errCode = ErrorDetail.DataImportError;
                error.errMsg  = ErrorDetail.GetMsg(error.errCode);
                errs.Add("Error #" + error.errCode.ToString() + "!" + error.errMsg + ". " + ex.Message);
                ViewData["ErrorList"] = errs;
                return(View(model));
            }
            model._tb_College = db.tb_College;
            return(View(model));
        }
Exemplo n.º 13
0
        public ActionResult CreateActivity([Bind(Include = "_ActivityName,_ActivityDate,_ActivityNote,_CollegeID,_CampusID,_Callback,_MemberId,_ReturnCollegeID")] ActivityModels model, FormCollection formCollection)
        {
            Error error = new Error();

            error.errCode = ErrorDetail.Success;
            error.errMsg  = ErrorDetail.GetMsg(error.errCode);
            List <string> errs = new List <string>();

            model._Colleges = new List <SelectListItem>
            {
                new SelectListItem()
                {
                    Value = "0", Text = "-- Select One --"
                }
            }.Concat(db.tb_College.Select(x => new SelectListItem
            {
                Value = x.CollegeID.ToString(), Text = x.CollegeName
            }));
            model._Campuses = new SelectList(db.tb_Campus.Where(s => s.CollegeID == model._CollegeID).OrderBy(s => s.CampusName), "CampusID", "CampusName");

            var userId = HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId();

            using (LRCEntities context = new LRCEntities())
            {
                tb_Activity tb_Activity = new tb_Activity
                {
                    ActivityName  = model._ActivityName,
                    ActivityDate  = model._ActivityDate,
                    CampusID      = model._CampusID,
                    ActivityNote  = model._ActivityNote,
                    AddedBy       = userId,
                    AddedDateTime = DateTime.UtcNow
                };
                context.tb_Activity.Add(tb_Activity);
                try
                {
                    context.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    error.errCode = ErrorDetail.DataImportError;
                    error.errMsg  = ErrorDetail.GetMsg(error.errCode);
                    foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
                    {
                        error.errMsg += ". Object: " + validationError.Entry.Entity.ToString();
                        foreach (DbValidationError err in validationError.ValidationErrors)
                        {
                            error.errMsg += ". " + err.ErrorMessage;
                        }
                    }
                    errs.Add("Error #" + error.errCode.ToString() + "!" + error.errMsg);
                    ViewData["ErrorList"] = errs;
                    return(View(model));
                }
            }
            switch (model._Callback)
            {
            case "AddActivityByMember":
                return(RedirectToAction("AddActivityByMember"));

            case "AddActivity":
                return(RedirectToAction("AddActivity", new { @id = model._MemberId }));

            case "AddPersonAssessmentActivity":
                return(RedirectToAction("AddPersonAssessmentActivity", "Assessment", new { @id = model._MemberId, CollegeID = model._ReturnCollegeID }));

            default:
                break;
            }
            return(View(model));
        }
Exemplo n.º 14
0
        public async Task <ActionResult> Register(RegisterViewModel model, string Roles)
        {
            SelectList roles = new SelectList(db.AspNetRoles, "Id", "Name");

            ViewBag.Roles = roles;
            var _users = db.AspNetUsers.ToList();
            List <SelectListItem> _UsersRoles = new List <SelectListItem>();

            foreach (var _user in _users)
            {
                var currentRoles = UserManager.GetRolesAsync(_user.Id);
                _UsersRoles.Add(new SelectListItem()
                {
                    Text = _user.UserName, Value = currentRoles.Result.FirstOrDefault()
                });
            }
            ViewBag.UsersAndRoles = _UsersRoles;
            ExcelMembers excelMembers = new ExcelMembers();

            Error error = excelMembers.SplitFullName(model.UserLastFirstName, null, 0, out string lastName, out string firstName, out string middleName);

            if (error.errCode != ErrorDetail.Success)
            {
                ModelState.AddModelError("User Name Error", error.errMsg + ". Please enter last name and first name, separated by a comma.");
                return(View(model));
            }

            if (ModelState.IsValid)
            {
                string selectedRole = roles.Where(t => t.Value == Roles).FirstOrDefault().Text;
                var    user         = new ApplicationUser {
                    UserName = model.Email + ":" + selectedRole, Email = model.Email
                };                                                                                                   // placing selected Role Name to User Name in AspNetUsers table
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    using (LRCEntities context = new LRCEntities())
                    {
                        try
                        {
                            AspNetUsers aUser = context.AspNetUsers.Where(s => s.Email.ToUpper() == model.Email.ToUpper()).FirstOrDefault();
                            aUser.LastFirstName = model.UserLastFirstName;
                            context.SaveChanges();
                        }
                        catch (DbEntityValidationException ex)
                        {
                            error.errCode = ErrorDetail.DataImportError;
                            error.errMsg  = ErrorDetail.GetMsg(error.errCode);
                            foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
                            {
                                error.errMsg += ". Object: " + validationError.Entry.Entity.ToString();
                                foreach (DbValidationError err in validationError.ValidationErrors)
                                {
                                    error.errMsg += ". " + err.ErrorMessage;
                                }
                            }
                        }
                    }
                    if (error.errCode != ErrorDetail.Success)
                    {
                        ModelState.AddModelError("User Name Update Failed", error.errMsg);
                        return(View(model));
                    }

                    return(RedirectToAction("RegistrationRequestSentToAdmin", "Account"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 15
0
        public ActionResult AddPersonAssessmentActivity(int id, string submit, int AssessmentNameID, string AssessedBy, int ActivityID,
                                                        int ActivityStatusID, int ValueID, AssessActivityModels model, FormCollection formCollection)
        {
            //if (id == null)
            //{
            //    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            //}
            Error error = new Error();

            error.errCode = ErrorDetail.Success;
            List <string> errs   = new List <string>();
            string        userId = HttpContext.GetOwinContext().Authentication.User.Identity.GetUserId();

            //string uLastFirstName = db.AspNetUsers.Where(s => s.Email == uName).FirstOrDefault().LastFirstName;

            //ViewBag.CollegeID = CollegeID;

            #region Prepare Model (ASSESSMENT Part)

            SelectList FeePayerAssess = new SelectList(db.tb_AssessmentName.OrderBy(s => s.AssessmentName), "AssessmentNameID", "AssessmentName", AssessmentNameID /* selected value */);
            ViewBag.AssessmentNameID = FeePayerAssess;

            SelectList AssessmentValue = new SelectList(db.tb_AssessmentValue, "ValueID", "ValueName", ValueID /* selected value */);
            ViewBag.ValueID = AssessmentValue;

            SelectList AspNetUsers = new SelectList(db.AspNetUsers.OrderBy(s => s.LastFirstName), "Id", "LastFirstName");
            ViewBag.AssessedBy = AspNetUsers;

            model._Assessment.ValueID          = ValueID;
            model._Assessment.AssessmentNameID = AssessmentNameID;
            model._Assessment.AssessedBy       = AssessedBy;
            model._Assessment.AddedDateTime    = DateTime.Now;
            model._MemberAssessments           = db.tb_Assessment.Where(f => f.tb_MemberMaster.MemberID == id).ToList();

            #endregion

            #region Prepare Model (ACTIVITY Part)

            model._ActivityStatus = db.tb_ActivityStatus.ToList();

            ViewBag.ActivityStatusAfter = new List <SelectListItem>
            {
                new SelectListItem {
                    Value = "0", Text = "Participated", Selected = false
                },
                new SelectListItem {
                    Value = "1", Text = "Not Participated", Selected = false
                }
            };

            SelectList     Activities  = new SelectList(db.tb_Activity.OrderBy(s => s.ActivityName), "ActivityID", "ActivityName");
            SelectListItem selListItem = new SelectListItem()
            {
                Value = "0", Text = " Select Activity "
            };
            ViewBag.ActivityID = CommonFunctions.AddFirstItem(Activities, selListItem);

            model._MemberActivity = db.tb_MemberActivity.Where(s => s.MemberID == id).ToList();

            tb_MemberMaster fm = db.tb_MemberMaster.Find(id);
            ViewBag.MemberName = fm.FirstName + " " + fm.LastName;

            #endregion

            if (submit == "Submit") //Adding Assessment
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        model._Assessment.AddedBy = userId;
                        db.tb_Assessment.Add(model._Assessment);
                        db.SaveChanges();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        error.errCode = ErrorDetail.DataImportError;
                        error.errMsg  = ErrorDetail.GetMsg(error.errCode);
                        foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
                        {
                            error.errMsg += ". Object: " + validationError.Entry.Entity.ToString();
                            foreach (DbValidationError err in validationError.ValidationErrors)
                            {
                                error.errMsg += ". " + err.ErrorMessage;
                            }
                        }
                        errs.Add("Error #" + error.errCode.ToString() + "!" + error.errMsg);
                        ViewData["AssessmentErrorList"] = errs;
                        return(View(model));
                    }

                    model._MemberAssessments = db.tb_Assessment.Where(f => f.tb_MemberMaster.MemberID == id).ToList();
                    return(View(model));
                }
                else
                {
                    error.errCode = ErrorDetail.DataImportError;
                    error.errMsg  = ErrorDetail.GetMsg(error.errCode);
                    foreach (var state in ModelState)
                    {
                        foreach (var err in state.Value.Errors)
                        {
                            error.errMsg += ". " + err.ErrorMessage;
                        }
                    }
                    errs.Add("Error #" + error.errCode.ToString() + "!" + error.errMsg);
                    ViewData["AssessmentErrorList"] = errs;
                    return(View(model));
                }
            }

            else if (submit == "Assign") //Adding Person to Activity
            {
                if (ModelState.IsValid)
                {
                    bool?isParticipated = null;
                    if (formCollection["afterTheFact"] == "0")
                    {
                        isParticipated = true;
                    }
                    else if (formCollection["afterTheFact"] == "1")
                    {
                        isParticipated = false;
                    }

                    ActivityByMemberModels activityCRUD = new ActivityByMemberModels();
                    errs = activityCRUD.AddEditActivity(id, ActivityID, ActivityStatusID, isParticipated, model._Activity.ActivityDate, model._Activity.ActivityNote, userId);

                    if (errs == null || errs.Count == 0)
                    {
                        return(RedirectToAction("MembersBySchool", "Home", new { @CollegeID = model._CollegeID }));
                    }
                    else
                    {
                        ViewData["ErrorList"] = errs;

                        ActivityByMemberModels memberActivities = new ActivityByMemberModels();
                        memberActivities.MemberCollection = memberActivities.GetFullListOfMembers();

                        return(View(memberActivities));
                    }
                }
                else
                {
                    error.errCode = ErrorDetail.DataImportError;
                    error.errMsg  = ErrorDetail.GetMsg(error.errCode);
                    foreach (var state in ModelState)
                    {
                        foreach (var err in state.Value.Errors)
                        {
                            error.errMsg += ". " + err.ErrorMessage;
                        }
                    }
                    errs.Add("Error #" + error.errCode.ToString() + "!" + error.errMsg);
                    ViewData["ErrorList"] = errs;

                    ActivityByMemberModels memberActivities = new ActivityByMemberModels();
                    memberActivities.MemberCollection = memberActivities.GetFullListOfMembers();

                    return(View(memberActivities));
                }                //if (ModelState.IsValid)
                //{
                //    try
                //    {
                //        tb_Activity activity = db.tb_Activity.Find(ActivityID);
                //        activity.ActivityDate = model._Activity.ActivityDate;
                //        activity.ActivityNote = model._Activity.ActivityNote;
                //        activity.ModifiedDateTime = DateTime.UtcNow;
                //        activity.ModifiedBy = userId;

                //        tb_MemberActivity oldMemberActivity = db.tb_MemberActivity.Where(p => p.ActivityID == ActivityID && p.MemberID == id).FirstOrDefault(); //id = AssessActivity._Assessment.MemberID (changed to id)
                //        if (oldMemberActivity == null) //Action isnt assigned for this member
                //        {
                //            tb_MemberActivity memberActivity = new tb_MemberActivity();
                //            memberActivity.MemberID = id ?? default(int); //id = AssessActivity._Assessment.MemberID (changed to id);
                //            memberActivity.ActivityID = ActivityID;
                //            memberActivity.ActivityStatusID = ActivityStatusID;
                //            if (ActivityStatusID == 1) // 1 - Committed
                //            {
                //                memberActivity.Membership = true;
                //                memberActivity.MembershipCommitment++;
                //            }
                //            else
                //                memberActivity.Membership = false;

                //            db.tb_MemberActivity.Add(memberActivity);
                //        }
                //        else
                //        {
                //            if (ActivityStatusID == 1) // 1 - Committed
                //            {
                //                oldMemberActivity.Membership = true;
                //                oldMemberActivity.MembershipCommitment++;
                //            }
                //            else
                //            {
                //                oldMemberActivity.Membership = false;
                //                if (oldMemberActivity.ActivityStatusID == 1 && oldMemberActivity.MembershipCommitment > 0) //commited before so reduce qty of commitments
                //                    oldMemberActivity.MembershipCommitment--;
                //            }
                //            oldMemberActivity.ActivityStatusID = ActivityStatusID;
                //            db.Entry(oldMemberActivity).State = EntityState.Modified;
                //        }
                //        db.SaveChanges();
                //        model._MemberActivity = db.tb_MemberActivity.Where(s => s.MemberID == id).ToList();
                //    }
                //    catch (DbEntityValidationException ex)
                //    {
                //        error.errCode = ErrorDetail.DataImportError;
                //        error.errMsg = ErrorDetail.GetMsg(error.errCode);
                //        foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
                //        {
                //            error.errMsg += ". Object: " + validationError.Entry.Entity.ToString();
                //            foreach (DbValidationError err in validationError.ValidationErrors)
                //            {
                //                error.errMsg += ". " + err.ErrorMessage;
                //            }
                //        }
                //        errs.Add("Error #" + error.errCode.ToString() + "!" + error.errMsg);
                //        ViewData["ActivityErrorList"] = errs;
                //        return View(model);
                //    }
                //}
            }
            else
            {
                error.errCode = ErrorDetail.DataImportError;
                error.errMsg  = ErrorDetail.GetMsg(error.errCode);
                foreach (var state in ModelState)
                {
                    foreach (var err in state.Value.Errors)
                    {
                        error.errMsg += ". " + err.ErrorMessage;
                    }
                }
                errs.Add("Error #" + error.errCode.ToString() + "!" + error.errMsg);
                ViewData["ActivityErrorList"] = errs;
                return(View(model));
            }

            return(View(model));
            //return RedirectToAction("AddPersonAssessmentActivity");
        }
Exemplo n.º 16
0
        //Get tb_MemberAddress record for current Member
        //Assign MemberID for existing Member or return tb_MemberAddress.MemberID = 0 for new one
        public static List <string> AssignAddress(string _HomeStreet1, string _HomeStreet2, string city, string st, string postal, int addressTypeID,
                                                  bool isAdressPrimary, string source, int sourceID, int mID, string userId)
        {
            Error error = new Error();

            error.errCode = ErrorDetail.Success;
            error.errMsg  = ErrorDetail.GetMsg(error.errCode);
            List <string> errs = new List <string>();

            //int cityId = GetCityID(city);

            using (LRCEntities context = new LRCEntities())
            {
                // Check if address(es) exist for current member
                var memberAddresses = context.tb_MemberAddress.Where(s => s.MemberID == mID).OrderByDescending(s => s.CreatedDateTime).ToArray();
                var stateNo         = 1;
                try
                {
                    stateNo = context.tb_States.Where(x => x.StateCode.ToUpper() == st.ToUpper()).FirstOrDefault().StateID;
                }
                catch
                {
                    stateNo = 1;
                }

                if (memberAddresses.Count() > 0) //Current member has address(es)
                {
                    int recornNumber = 0;
                    foreach (var ma in memberAddresses)
                    {
                        if (++recornNumber <= MvcApplication.MaxRecordsInAddressHistory) //Leaving 5 records only and updating them
                        {
                            if (isAdressPrimary)
                            {
                                ma.IsPrimary = false;   //Set IsPrimary to false for all of addresses of current member.
                                if (ma.EndDate == null) //EndDate == null means current Member Address is actual (isn't record for history)
                                {
                                    ma.EndDate = DateTime.UtcNow;
                                }
                            }
                        }
                        else //Remove the excess. In the history we leave only MaxRecordsInAddressHistory = 5 entries
                        {
                            context.tb_MemberAddress.Remove(ma);
                        }
                        try
                        {
                            context.SaveChanges();
                        }
                        catch (DbEntityValidationException ex)
                        {
                            error.errCode = ErrorDetail.DataImportError;
                            error.errMsg  = ErrorDetail.GetMsg(error.errCode);
                            foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
                            {
                                error.errMsg += ". Object: " + validationError.Entry.Entity.ToString();
                                foreach (DbValidationError err in validationError.ValidationErrors)
                                {
                                    error.errMsg += ". " + err.ErrorMessage;
                                }
                            }
                            errs.Add("Error #" + error.errCode.ToString() + "!" + error.errMsg);
                            return(errs);
                        }
                    }
                }

                //Assign new address to the current Member
                //Check dublicates
                memberAddresses = memberAddresses.Where(s => s.MemberID == mID && s.HomeStreet1 == _HomeStreet1 &&
                                                        s.City == city && s.ZipCode == postal).ToArray();
                if (memberAddresses.Count() == 0) // add new address
                {
                    tb_MemberAddress address = new tb_MemberAddress()
                    {
                        MemberID        = mID,
                        HomeStreet1     = _HomeStreet1,
                        HomeStreet2     = _HomeStreet2,
                        City            = city,
                        ZipCode         = postal,
                        StateID         = stateNo,
                        Country         = "USA",
                        SourceID        = sourceID, // 1 -Card/Form, 2 - Employer
                        Source          = userId,
                        IsPrimary       = isAdressPrimary,
                        AddressTypeID   = addressTypeID,
                        CreatedDateTime = DateTime.Now,
                        ModifiedBy      = userId,
                        StartDate       = DateTime.UtcNow,
                        EndDate         = null
                    };
                    if (!isAdressPrimary)
                    {
                        address.EndDate = DateTime.UtcNow;
                    }

                    context.tb_MemberAddress.Add(address);
                }
                else // edit old address
                {
                    var address = context.tb_MemberAddress.Where(s => s.MemberID == mID && s.HomeStreet1 == _HomeStreet1 &&
                                                                 s.City == city && s.ZipCode == postal).FirstOrDefault();
                    address.HomeStreet2      = _HomeStreet2;
                    address.StateID          = stateNo;
                    address.Country          = "USA";
                    address.SourceID         = sourceID;
                    address.Source           = userId;
                    address.IsPrimary        = isAdressPrimary;
                    address.AddressTypeID    = addressTypeID;
                    address.ModifiedBy       = userId;
                    address.ModifiedDateTime = DateTime.Now;
                    address.StartDate        = DateTime.UtcNow;
                    address.EndDate          = null;
                    if (!isAdressPrimary)
                    {
                        address.EndDate = DateTime.UtcNow;
                    }
                }

                try
                {
                    context.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    error.errCode = ErrorDetail.DataImportError;
                    error.errMsg  = ErrorDetail.GetMsg(error.errCode);
                    foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
                    {
                        error.errMsg += ". Object: " + validationError.Entry.Entity.ToString();
                        foreach (DbValidationError err in validationError.ValidationErrors)
                        {
                            error.errMsg += ". " + err.ErrorMessage;
                        }
                    }
                    errs.Add("Error #" + error.errCode.ToString() + "!" + error.errMsg);
                    return(errs);
                }
            }
            return(errs);
        }
Exemplo n.º 17
0
        //Assign tb_MemberEmail record for current Member
        public static List <string> AssignEmail(string email, int emailTypeID, bool isEmailPrimary, string source, int mID, string userId)
        {
            Error error = new Error();

            error.errCode = ErrorDetail.Success;
            error.errMsg  = ErrorDetail.GetMsg(error.errCode);
            List <string> errs = new List <string>();

            using (LRCEntities context = new LRCEntities())
            {
                // Check if email(s) exist for current member
                var memberEmailAddresses = context.tb_MemberEmail.Where(s => s.MemberID == mID).OrderByDescending(s => s.CreatedDateTime).ToArray();

                if (memberEmailAddresses.Count() > 0) //Current member has email(s)
                {
                    int recornNumber = 0;
                    foreach (var me in memberEmailAddresses)
                    {
                        if (++recornNumber <= MvcApplication.MaxRecordsInEmailHistory) //Leaving 10 records only and updating them
                        {
                            if (isEmailPrimary)
                            {
                                me.IsPrimary = false;   //Set IsPrimary to false for all other member email from history
                                if (me.EndDate == null) //EndDate == null means current Member email is actual (isn't record for history)
                                {
                                    me.EndDate = DateTime.UtcNow;
                                }
                            }
                        }
                        else //Remove the excess. In the history we leave only MaxRecordsInEmailHistory = 10 entries
                        {
                            context.tb_MemberEmail.Remove(me);
                        }
                        try
                        {
                            context.SaveChanges();
                        }
                        catch (DbEntityValidationException ex)
                        {
                            error.errCode = ErrorDetail.DataImportError;
                            error.errMsg  = ErrorDetail.GetMsg(error.errCode);
                            foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
                            {
                                error.errMsg += ". Object: " + validationError.Entry.Entity.ToString();
                                foreach (DbValidationError err in validationError.ValidationErrors)
                                {
                                    error.errMsg += ". " + err.ErrorMessage;
                                }
                            }
                            errs.Add("Error #" + error.errCode.ToString() + "!" + error.errMsg);
                            return(errs);
                        }
                    }
                }

                //Assign new email to a current Member
                //Check dublicates
                memberEmailAddresses = memberEmailAddresses.Where(s => s.MemberID == mID && s.EmailAddress == email).ToArray();
                if (memberEmailAddresses.Count() == 0) // add new email
                {
                    tb_MemberEmail emailAddress = new tb_MemberEmail()
                    {
                        MemberID        = mID,
                        EmailAddress    = email,
                        IsPrimary       = isEmailPrimary,
                        EmailTypeID     = emailTypeID,
                        Source          = source,
                        CreatedDateTime = DateTime.Now,
                        ModifiedBy      = userId,
                        StartDate       = DateTime.UtcNow,
                        EndDate         = null
                    };
                    if (!isEmailPrimary)
                    {
                        emailAddress.EndDate = DateTime.UtcNow;
                    }
                    context.tb_MemberEmail.Add(emailAddress);
                }
                else // edit old email
                {
                    var emailAddress = context.tb_MemberEmail.Where(s => s.MemberID == mID && s.EmailAddress == email).FirstOrDefault();
                    emailAddress.IsPrimary        = isEmailPrimary;
                    emailAddress.EmailTypeID      = emailTypeID;
                    emailAddress.Source           = source;
                    emailAddress.ModifiedBy       = userId;
                    emailAddress.ModifiedDateTime = DateTime.Now;
                    emailAddress.StartDate        = DateTime.UtcNow;
                    emailAddress.EndDate          = null;
                    if (!isEmailPrimary)
                    {
                        emailAddress.EndDate = DateTime.UtcNow;
                    }
                }

                try
                {
                    context.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    error.errCode = ErrorDetail.DataImportError;
                    error.errMsg  = ErrorDetail.GetMsg(error.errCode);
                    foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
                    {
                        error.errMsg += ". Object: " + validationError.Entry.Entity.ToString();
                        foreach (DbValidationError err in validationError.ValidationErrors)
                        {
                            error.errMsg += ". " + err.ErrorMessage;
                        }
                    }
                    errs.Add("Error #" + error.errCode.ToString() + "!" + error.errMsg);
                    return(errs);
                }
                return(errs);
            }
        }