public OperationStatus ActionCarPoolRequest(CarPoolAssociationCustomModel model)
        {
            OperationStatus status   = OperationStatus.Error;
            DateTime        PoolDate = Convert.ToDateTime(model.DDate);

            try
            {
                using (dbcontext = new CarPoolApplicationEntities())
                {
                    var updatePoolInfo = dbcontext.tblCarPoolMemberAssociations.FirstOrDefault(x => x.AssociationId == model.AssociationId);
                    if (updatePoolInfo != null)
                    {
                        updatePoolInfo.IsApproved = model.IsApproved;

                        updatePoolInfo.ModifiedBy   = model.ModifiedBy;
                        updatePoolInfo.ModifiedDate = DateTime.Now;

                        dbcontext.SaveChanges();
                        status = OperationStatus.Update;
                    }
                    else
                    {
                        status = OperationStatus.Duplicate;
                    }
                }
            }
            catch (Exception ex)
            {
                dbcontext.Dispose();
                status = OperationStatus.Exception;
                throw ex;
            }

            return(status);
        }
        /// <summary>
        /// This method is used to save new pool info
        /// </summary>
        /// <returns></returns>
        public OperationStatus SaveCarPoolApplication(CarPoolRegistrationCustomModel model)
        {
            OperationStatus status = OperationStatus.Error;

            try
            {
                using (dbcontext = new CarPoolApplicationEntities())
                {
                    if (model.Id == 0)
                    {
                        tblCarPoolRegistration _addCarPool = new tblCarPoolRegistration
                        {
                            MemberId       = model.MemberId,
                            Source         = model.Source,
                            Destination    = model.Destination,
                            PoolDate       = model.PoolDate,
                            Time           = model.Time,
                            Charges        = model.Charges,
                            SeatsAvailable = model.SeatsAvailable,

                            IsActive     = true,
                            IsDeleted    = false,
                            CreatedDate  = DateTime.Now,
                            CreatedBy    = model.CreatedBy,
                            ModifiedDate = DateTime.Now,
                            ModifiedBy   = model.ModifiedBy,
                        };
                        dbcontext.tblCarPoolRegistrations.Add(_addCarPool);
                        dbcontext.SaveChanges();

                        status = OperationStatus.Success;
                    }
                    else
                    {
                        var updatePoolInfo = dbcontext.tblCarPoolRegistrations.FirstOrDefault(m => m.Id == model.Id);
                        if (updatePoolInfo != null)
                        {
                            updatePoolInfo.MemberId       = model.MemberId;
                            updatePoolInfo.Source         = model.Source;
                            updatePoolInfo.Destination    = model.Destination;
                            updatePoolInfo.PoolDate       = model.PoolDate;
                            updatePoolInfo.Time           = model.Time;
                            updatePoolInfo.Charges        = model.Charges;
                            updatePoolInfo.SeatsAvailable = model.SeatsAvailable;

                            updatePoolInfo.ModifiedBy   = model.ModifiedBy;
                            updatePoolInfo.ModifiedDate = DateTime.Now;

                            dbcontext.SaveChanges();
                            status = OperationStatus.Update;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                dbcontext.Dispose();
                status = OperationStatus.Exception;
                throw ex;
            }

            return(status);
        }
Пример #3
0
        /// <summary>
        /// This method is used to save new members
        /// </summary>
        /// <returns></returns>
        public OperationStatus SaveApplicationUser(ApplicationUserModel applicationUserModel)
        {
            OperationStatus status = OperationStatus.Error;

            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    using (dbcontext = new CarPoolApplicationEntities())
                    {
                        if (applicationUserModel.ApplicationUserId == 0)
                        {
                            var rs = dbcontext.tblApplicationUsers.FirstOrDefault(x => x.UserName == applicationUserModel.UserName && x.IsDeleted == false);
                            if (rs == null)
                            {
                                tblMember _addMember = new tblMember
                                {
                                    Name        = applicationUserModel.Name,
                                    EmailId     = applicationUserModel.EmailId,
                                    MobileNo    = applicationUserModel.MobileNo,
                                    Gender      = applicationUserModel.Gender,
                                    DateOfBirth = applicationUserModel.DateOfBirth,
                                    Address     = applicationUserModel.Address,
                                    FatherName  = applicationUserModel.FatherName,
                                    MotherName  = applicationUserModel.MotherName,

                                    IsActive     = true,
                                    IsDeleted    = false,
                                    CreatedDate  = DateTime.Now,
                                    CreatedBy    = applicationUserModel.CreatedBy,
                                    ModifiedDate = DateTime.Now,
                                    ModifyBy     = applicationUserModel.ModifyBy,
                                };
                                dbcontext.tblMembers.Add(_addMember);
                                dbcontext.SaveChanges();
                                int userid = _addMember.MemberId;

                                tblApplicationUser _applicationUserinfo = new tblApplicationUser
                                {
                                    Name            = applicationUserModel.Name,
                                    EmailId         = applicationUserModel.EmailId,
                                    MobileNo        = applicationUserModel.MobileNo,
                                    UserIdentityKey = userid,
                                    UserName        = applicationUserModel.UserName,
                                    Password        = applicationUserModel.Password,

                                    IsActive     = true,
                                    IsDeleted    = false,
                                    CreatedDate  = DateTime.Now,
                                    CreatedBy    = applicationUserModel.CreatedBy,
                                    ModifiedDate = DateTime.Now,
                                    ModifyBy     = applicationUserModel.ModifyBy,
                                };

                                dbcontext.tblApplicationUsers.Add(_applicationUserinfo);
                                dbcontext.SaveChanges();

                                status = OperationStatus.Success;
                                ts.Complete();
                            }
                            else
                            {
                                status = OperationStatus.Duplicate;
                                //ts.Dispose();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    dbcontext.Dispose();
                    status = OperationStatus.Exception;
                    ts.Dispose();
                    throw ex;
                }
            }
            return(status);
        }
        /// <summary>
        /// This method is used to save car pool requests
        /// </summary>
        /// <returns></returns>
        public OperationStatus SubmitCarPoolRequest(CarPoolAssociationCustomModel model)
        {
            OperationStatus status   = OperationStatus.Error;
            DateTime        PoolDate = Convert.ToDateTime(model.DDate);

            try
            {
                using (dbcontext = new CarPoolApplicationEntities())
                {
                    if (model.AssociationId == 0)
                    {
                        var rs = dbcontext.tblCarPoolMemberAssociations.FirstOrDefault(x => x.MemberId == model.MemberId &&
                                                                                       x.CarPoolId == model.CarPoolId &&
                                                                                       (x.DDate.Value.Year == PoolDate.Year && x.DDate.Value.Month == PoolDate.Month && x.DDate.Value.Day == PoolDate.Day)
                                                                                       );
                        if (rs == null)
                        {
                            tblCarPoolMemberAssociation _addCarPool = new tblCarPoolMemberAssociation
                            {
                                MemberId    = model.MemberId,
                                CarPoolId   = model.CarPoolId,
                                DDate       = PoolDate,
                                Description = model.Description,
                                IsApproved  = 1,

                                IsActive     = true,
                                IsDeleted    = false,
                                CreatedDate  = DateTime.Now,
                                CreatedBy    = model.CreatedBy,
                                ModifiedDate = DateTime.Now,
                                ModifiedBy   = model.ModifiedBy,
                            };
                            dbcontext.tblCarPoolMemberAssociations.Add(_addCarPool);
                            dbcontext.SaveChanges();

                            status = OperationStatus.Success;
                        }
                        else
                        {
                            status = OperationStatus.Duplicate;
                        }
                    }
                    else
                    {
                        var rs = dbcontext.tblCarPoolMemberAssociations.FirstOrDefault(m => m.IsDeleted == false &&
                                                                                       m.MemberId == model.MemberId &&
                                                                                       m.CarPoolId == model.CarPoolId &&
                                                                                       (m.DDate.Value.Year == PoolDate.Year && m.DDate.Value.Month == PoolDate.Month && m.DDate.Value.Day == PoolDate.Day) &&
                                                                                       m.AssociationId != model.AssociationId
                                                                                       );
                        if (rs == null)
                        {
                            var updatePoolInfo = dbcontext.tblCarPoolMemberAssociations.FirstOrDefault(x => x.AssociationId == model.AssociationId);
                            if (updatePoolInfo != null)
                            {
                                updatePoolInfo.MemberId    = model.MemberId;
                                updatePoolInfo.CarPoolId   = model.CarPoolId;
                                updatePoolInfo.DDate       = PoolDate;
                                updatePoolInfo.Description = model.Description;

                                updatePoolInfo.ModifiedBy   = model.ModifiedBy;
                                updatePoolInfo.ModifiedDate = DateTime.Now;

                                dbcontext.SaveChanges();
                                status = OperationStatus.Update;
                            }
                        }
                        else
                        {
                            status = OperationStatus.Duplicate;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                dbcontext.Dispose();
                status = OperationStatus.Exception;
                throw ex;
            }

            return(status);
        }