コード例 #1
0
        /// <summary>
        /// Created By : Ashwajit Bansod
        /// Created Date : 18-OCT-2018
        /// Created for : To approve miscellaneous data.
        /// </summary>
        /// <param name="Obj"></param>
        /// <returns></returns>
        public bool ApproveMiscellaneous(List <MiscellaneousListModel> Obj, string UserName, long UserId, long LocationId, long MiscQbkId, long VendorDetailsId)
        {
            bool     IsApproved     = false;
            long     MISNumber      = 0;
            decimal? calculatedAmt  = 0;
            string   MISID          = "";
            var      objDAR         = new DARModel();
            var      CommonManager  = new CommonMethodManager();
            DateTime date           = new DateTime();
            long     CreatedBy      = 0;
            long     Location       = 0;
            bool     GetOnceData    = false;
            var      UserDetail     = new UserModel();
            var      LocationDetail = new LocationMaster();
            string   Status         = "Approved";

            try
            {
                if (Obj.Count > 0)
                {
                    foreach (var item in Obj)
                    {
                        MISID = item.MISId;
                        string id = item.MISId.Split('S')[1];
                        MISNumber       = Convert.ToInt64(id);
                        calculatedAmt  += item.InvoiceAmount;
                        Location        = item.LocationId;
                        date            = Convert.ToDateTime(item.MISDate);
                        CreatedBy       = item.Vendor;
                        objDAR.TaskType = (long)TaskTypeCategory.MiscellaneousReject;
                        if (item.Status == "N")
                        {
                            Status          = "Reject";
                            calculatedAmt  -= item.InvoiceAmount;
                            objDAR.TaskType = (long)TaskTypeCategory.MiscellaneousReject;
                        }
                        var saveApprove = _workorderems.spSetApprovalForMiscellaneous(item.MId, item.Comment, item.Status, UserId);
                        if (GetOnceData == false)
                        {
                            GetOnceData = true;
                            UserDetail  = _workorderems.UserRegistrations.Join(_workorderems.LogMiscellaneous, u => u.UserId, m => m.LMIS_ModifiedBy, (u, m) => new { u, m }).
                                          Where(x => x.m.LMIS_MIS_Id == MISNumber).
                                          Select(x => new UserModel()
                            {
                                UserName = x.u.FirstName + " " + x.u.LastName,
                                Email    = x.u.UserEmail,
                                Location = x.m.LMIS_LocationId
                            }).FirstOrDefault();
                            LocationDetail = _workorderems.LocationMasters.Where(x => x.LocationId == UserDetail.Location &&
                                                                                 x.IsDeleted == false).FirstOrDefault();
                        }

                        #region Save DAR
                        objDAR.ActivityDetails = DarMessage.MiscellaneousApproveReject(LocationDetail.LocationName, MISID, Status);
                        objDAR.UserId          = UserId;
                        objDAR.CreatedBy       = UserId;
                        objDAR.LocationId      = UserDetail.Location;
                        objDAR.CreatedOn       = DateTime.UtcNow;
                        CommonManager.SaveDAR(objDAR);
                        #endregion DAR
                    }
                    string Action   = "I";
                    var    saveBill = _workorderems.spSetBill(Action, MiscQbkId, null, MISNumber, null, VendorDetailsId, Location, "MIS", calculatedAmt,
                                                              calculatedAmt, date, null, CreatedBy, null, "Y");
                    IsApproved = true;
                }
                else
                {
                    IsApproved = true;
                }
                if (IsApproved == true)
                {
                    #region Email
                    var objEmailLogRepository = new EmailLogRepository();
                    var objEmailReturn        = new List <EmailToManagerModel>();
                    var objListEmailog        = new List <EmailLog>();
                    var objTemplateModel      = new TemplateModel();
                    if (IsApproved == true)
                    {
                        var userData = _workorderems.UserRegistrations.Join(_workorderems.LogMiscellaneous, u => u.UserId, m => m.LMIS_ModifiedBy, (u, m) => new { u, m }).
                                       Where(x => x.m.LMIS_MIS_Id == MISNumber).FirstOrDefault();
                        //Select(x => new UserModel()
                        //{
                        //    UserName = x.u.FirstName + " " + x.u.LastName,
                        //    Email = x.u.UserEmail,
                        //    Location = x.m.LMIS_LocationId,

                        //}).FirstOrDefault();
                        var locationName = _workorderems.LocationMasters.Where(x => x.LocationId == userData.m.LMIS_LocationId &&
                                                                               x.IsDeleted == false).FirstOrDefault();
                        if (userData != null)
                        {
                            bool IsSent         = false;
                            var  objEmailHelper = new EmailHelper();
                            objEmailHelper.emailid       = userData.u.SubscriptionEmail;
                            objEmailHelper.LocationName  = locationName.LocationName;
                            objEmailHelper.UserName      = userData.u.FirstName + " " + userData.u.LastName;
                            objEmailHelper.MISId         = MISID;
                            objEmailHelper.MailType      = "APPROVEMISCELLANEOUS";
                            objEmailHelper.SentBy        = UserId;
                            objEmailHelper.LocationID    = userData.m.LMIS_LocationId;
                            objEmailHelper.TimeAttempted = DateTime.UtcNow.ToMobileClientTimeZone(objTemplateModel.TimeZoneName, objTemplateModel.TimeZoneOffset, objTemplateModel.IsTimeZoneinDaylight, false).ToString();
                            IsSent = objEmailHelper.SendEmailWithTemplate();

                            //Push Notification
                            if (userData.u.DeviceId != null)
                            {
                                string message = PushNotificationMessages.MiscellaneousApprovedReject(objEmailHelper.LocationName, MISID, Status, objEmailHelper.UserName);
                                PushNotification.GCMAndroid(message, userData.u.DeviceId, objEmailHelper);
                            }
                            if (IsSent == true)
                            {
                                var objEmailog = new EmailLog();
                                try
                                {
                                    objEmailog.CreatedBy   = UserId;
                                    objEmailog.CreatedDate = DateTime.UtcNow;
                                    objEmailog.DeletedBy   = null;
                                    objEmailog.DeletedOn   = null;
                                    objEmailog.LocationId  = userData.m.LMIS_LocationId;
                                    objEmailog.ModifiedBy  = null;
                                    objEmailog.ModifiedOn  = null;
                                    objEmailog.SentBy      = UserId;
                                    objEmailog.SentEmail   = userData.u.SubscriptionEmail;
                                    objEmailog.Subject     = objEmailHelper.Subject;
                                    objEmailog.SentTo      = userData.u.UserId;
                                    objListEmailog.Add(objEmailog);
                                }
                                catch (Exception)
                                {
                                    throw;
                                }
                            }
                            using (var context = new workorderEMSEntities())
                            {
                                context.EmailLogs.AddRange(objListEmailog);
                                context.SaveChanges();
                            }
                            #endregion Email
                        }
                    }
                    else
                    {
                        IsApproved = true;
                    }
                }
                return(IsApproved);
            }
            catch (Exception ex)
            {
                Exception_B.Exception_B.exceptionHandel_Runtime(ex, "public MiscellaneousListDetails GetListMiscellaneous(long? UserId,long? Location, int? pageIndex, int? numberOfRows, string sortColumnName, string sortOrderBy, long? locationId, string textSearch, string statusType)", "Exception While Getting List of Miscellaneous details.", null);
                throw;
            }
        }