Пример #1
0
        public dynamic DeleteMemberRecordByID(int memberId)
        {
            List <MemberEntityModel> memberDetails = new List <MemberEntityModel>();

            try
            {
                using (MemberEligibilityEntities _db = new MemberEligibilityEntities())
                {
                    var memberAddEntity = _db.MemberEntities.Where(x => x.MemberID == memberId).FirstOrDefault();
                    _db.MemberEntities.Remove(memberAddEntity);
                    int iResult = _db.SaveChanges();
                    if (iResult > 0)
                    {
                        return(new
                        {
                            Valid = true,
                            Message = "Member removed successfully"
                        });
                    }
                    return(memberDetails);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        public dynamic SaveMethod(MemberEntityModel MemberEntityModel)
        {
            List <TechnologyEntityModel> memberDetails = new List <TechnologyEntityModel>();

            try
            {
                using (MemberEligibilityEntities _db = new MemberEligibilityEntities())
                {
                    //Time compare
                    int compareDates = DateTime.Compare(DateTime.Now, MemberEntityModel.DateOfBirth.Value);

                    if (compareDates < 0)
                    {
                        return(new
                        {
                            Valid = false,
                            Message = "Selected date must be greater than today's date."
                        });
                    }

                    int ageDiff = new DateTime((DateTime.Now - MemberEntityModel.DateOfBirth.Value).Ticks).Year;
                    if (ageDiff < 25)
                    {
                        return(new
                        {
                            Valid = false,
                            Message = "Date of birth greater than or equal to 25 years is valid."
                        });
                    }
                    if (MemberEntityModel.YearsOfExperience < 3)
                    {
                        return(new
                        {
                            Valid = false,
                            Message = "Years Of Experience must be greater than or equal to 3."
                        });
                    }

                    //Check result is valid or not
                    var memberAddEntity = _db.MemberEntities.Where(x => x.MemberID == MemberEntityModel.MemberID).FirstOrDefault();
                    if (memberAddEntity == null)
                    {
                        MemberEntity newMemberEntity = new MemberEntity();
                        newMemberEntity.MemberName        = MemberEntityModel.MemberName;
                        newMemberEntity.Qualification     = MemberEntityModel.Qualification;
                        newMemberEntity.TechnologyID      = MemberEntityModel.TechnologyID;
                        newMemberEntity.DateOfBirth       = MemberEntityModel.DateOfBirth.Value;
                        newMemberEntity.Qualification     = MemberEntityModel.Qualification;
                        newMemberEntity.YearsOfExperience = MemberEntityModel.YearsOfExperience;
                        _db.MemberEntities.Add(newMemberEntity);
                        int iResult = _db.SaveChanges();
                        if (iResult > 0)
                        {
                            return(new
                            {
                                Valid = true,
                                Message = "Member created Succesully"
                            });
                        }
                        else
                        {
                            return(new
                            {
                                Valid = false,
                                Message = "Member created Succesully"
                            });
                        }
                    }
                    else
                    {
                        memberAddEntity.MemberName        = MemberEntityModel.MemberName;
                        memberAddEntity.Qualification     = MemberEntityModel.Qualification;
                        memberAddEntity.TechnologyID      = MemberEntityModel.TechnologyID;
                        memberAddEntity.DateOfBirth       = MemberEntityModel.DateOfBirth.Value;
                        memberAddEntity.Qualification     = MemberEntityModel.Qualification;
                        memberAddEntity.YearsOfExperience = MemberEntityModel.YearsOfExperience;
                        int iResult = _db.SaveChanges();
                        if (iResult > 0)
                        {
                            return(new
                            {
                                Valid = true,
                                Message = "Member updated Succesully"
                            });
                        }
                        else
                        {
                            return(new
                            {
                                Valid = true,
                                Message = "Member updated Succesully"
                            });
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                return(new
                {
                    Valid = false,
                    Message = ex.Message.ToString()
                });

                throw ex;
            }
        }