public DataResult <MembersDetail> UpdateEmail(MembersDetail objMembersDetail) { DataResult <MembersDetail> Result = new DataResult <MembersDetail>(); try { using (var db = new SocietyDBEntities()) { //var transaction = db.Database.BeginTransaction(); MembersDetail objMember = db.MembersDetails.Where(x => x.memberId == objMembersDetail.memberId && x.societyId == objMembersDetail.societyId).FirstOrDefault(); if (objMember != null) { objMember.email = objMembersDetail.email; db.Entry(objMember).State = System.Data.EntityState.Modified; db.SaveChanges(); } else { Result.Message = "Member Not Found."; Result.MsgType = "E"; } } } catch (Exception ex) { Result.Message = ex.Message; Result.MsgType = "E"; } return(Result); }
public DataResult <MembersDetail> AddMember(MembersDetail objMembersDetail) { DataResult <MembersDetail> Result = new DataResult <MembersDetail>(); try { using (var db = new SocietyDBEntities()) { MembersDetail objMemberExists = db.MembersDetails.Where(x => x.flatNo == objMembersDetail.flatNo && x.societyId == objMembersDetail.societyId && x.isDeleted == false).FirstOrDefault(); if (objMemberExists == null) { MembersDetail objMemberUsernameExist = db.MembersDetails.Where(x => x.userName == objMembersDetail.userName).FirstOrDefault(); if (objMemberUsernameExist == null) { if (objMembersDetail.memberType != "SC") { DataResult <NumRange> ResultMemberID = Gb.GetNumRange("MB"); if (ResultMemberID.MsgType == "S") { objMembersDetail.memberId = ResultMemberID.StringResult; } else { Result.Message = ResultMemberID.Message; Result.MsgType = "E"; return(Result); } } objMembersDetail.createdDate = DateTime.Now; objMembersDetail.isDeleted = false; db.MembersDetails.Add(objMembersDetail); db.SaveChanges(); Result.Message = "Data Saved Successfully."; Result.MsgType = "S"; } else { Result.Message = "Username Already Exists."; Result.MsgType = "E"; } } else { Result.Message = "This Flat Is Owned By Another Member."; Result.MsgType = "E"; } } } catch (Exception ex) { Result.Message = ex.Message; Result.MsgType = "E"; } return(Result); }
public DataResult <NumRange> GetNumRange(string NumRangeCode) { try { using (var db = new SocietyDBEntities()) { NumRange objNumRange = db.NumRanges.Where(x => x.numRangeCode == NumRangeCode && x.isDeleted == false).FirstOrDefault(); if (objNumRange != null) { var NewNumber = objNumRange.currentNumber + 1; if (NewNumber > objNumRange.startNumber && NewNumber < objNumRange.endNumber) { objNumRange.currentNumber = NewNumber; db.Entry(objNumRange).State = System.Data.EntityState.Modified; db.SaveChanges(); var NewNumberString = NewNumber.ToString().PadLeft(8, '0'); NewNumberString = NumRangeCode + NewNumberString; Result.StringResult = NewNumberString; Result.Message = "NumRange Generated Successfully."; Result.MsgType = "S"; } else { Result.Message = "Numrange Exceeds.Kindly Contact Administration."; Result.MsgType = "E"; } } else { Result.Message = "Numrange Not Found.Kindly Contact Administration."; Result.MsgType = "E"; } } } catch (Exception ex) { Result.Message = ex.Message; Result.MsgType = "E"; } return(Result); }
public DataResult <AddSocietyCustomModel> AddSociety(AddSocietyCustomModel objSociety) { DataResult <AddSocietyCustomModel> Result = new DataResult <AddSocietyCustomModel>(); try { using (var db = new SocietyDBEntities()) { SocietyDetail objSocetyExists = db.SocietyDetails.Where(x => x.societyCode == objSociety.societyCode).FirstOrDefault(); if (objSocetyExists == null) { MembersDetail objMemberUsernameExist = db.MembersDetails.Where(x => x.userName == objSociety.userName).FirstOrDefault(); if (objMemberUsernameExist == null) { DataResult <NumRange> ResultSocietyID = Gb.GetNumRange("SC"); if (ResultSocietyID.MsgType == "S") { var societyId = ResultSocietyID.StringResult; DataResult <NumRange> ResultMemberID = Gb.GetNumRange("MB"); if (ResultMemberID.MsgType == "S") { var memberId = ResultMemberID.StringResult; SocietyDetail objSocietyDetail = new SocietyDetail(); objSocietyDetail.societyId = societyId; objSocietyDetail.societyCode = objSociety.societyCode; objSocietyDetail.societyName = objSociety.societyName; objSocietyDetail.secretory = memberId; objSocietyDetail.address = objSociety.address; objSocietyDetail.createdBy = objSociety.createdBy; objSocietyDetail.createdDate = DateTime.Now; objSocietyDetail.isDeleted = false; db.SocietyDetails.Add(objSocietyDetail); db.SaveChanges(); MembersDetail objMembersDetail = new MembersDetail(); objMembersDetail.memberId = memberId; objMembersDetail.memberName = objSociety.memberName; objMembersDetail.userName = objSociety.userName; objMembersDetail.password = objSociety.password; objMembersDetail.mobileNo = objSociety.mobileNo; objMembersDetail.memberType = objSociety.memberType; objMembersDetail.flatNo = objSociety.flatNo; objMembersDetail.email = objSociety.email; objMembersDetail.societyId = societyId; objMembersDetail.createdBy = objSociety.createdBy; MemberRepository objMemberRepo = new MemberRepository(); DataResult <MembersDetail> ResultMember = objMemberRepo.AddMember(objMembersDetail); if (ResultMember.MsgType == "S") { Result.Message = "Data Saved Successfully."; Result.MsgType = "S"; } else { Result.Message = ResultMember.Message; Result.MsgType = "E"; return(Result); } } else { Result.Message = ResultMemberID.Message; Result.MsgType = "E"; } } else { Result.Message = ResultSocietyID.Message; Result.MsgType = "E"; } } else { Result.Message = "Username Already Exists."; Result.MsgType = "E"; } } else { Result.Message = "Society Code Already Exists."; Result.MsgType = "E"; } } } catch (Exception ex) { Result.Message = ex.Message; Result.MsgType = "E"; } return(Result); }