コード例 #1
0
        /// <summary>
        /// Created By : Ashwajit Bansod
        /// Created Date : 20-OCT-2018
        /// Created For : To approve and reject bill
        /// </summary>
        /// <param name="Obj"></param>
        /// <param name="UserName"></param>
        /// <param name="UserId"></param>
        /// <param name="LocationId"></param>
        /// <returns></returns>
        public string ApproveBill(BillListApproveModel Obj, string UserName, long UserId, long LocationId)
        {
            bool   IsApproved    = false;
            string result        = "";
            var    objDAR        = new DARModel();
            var    CommonManager = new CommonMethodManager();
            string ApproveStatus = "";

            try
            {
                var userDataItem = _workorderems.UserRegistrations.Where(x => x.UserId == UserId &&
                                                                         x.IsDeleted == false && x.IsEmailVerify == true).FirstOrDefault();
                if (Obj != null)
                {
                    string Action = "I";
                    if (Obj.Comment == null)
                    {
                        Obj.Status    = "Y";
                        ApproveStatus = "Approved";
                    }
                    else
                    {
                        Obj.Status    = "N";
                        ApproveStatus = "Rejected";
                    }
                    var saveBillApprove = _workorderems.spSetApprovalForPreBill(Obj.LBLL_Id, Obj.Comment, Obj.Status, UserId);
                    //var saveApprove = _workorderems.spSetApprovalForBill(Obj.LBLL_Id, Obj.Comment,Obj.Status,UserId);
                    Obj.InvoiceDate = Convert.ToDateTime(Obj.BillDate);
                    var saveSetBill = _workorderems.spSetBill(Action, Obj.QuickBookBillId, null, null, Obj.BillId, Obj.VendorId, LocationId,
                                                              "Manual Bill", null, Obj.BillAmount, Obj.InvoiceDate,
                                                              Obj.BillImage, UserId, UserId, "Y");

                    IsApproved = true;
                    if (Obj.Comment == null)
                    {
                        result = CommonMessage.BillApprove();
                    }
                    else
                    {
                        result = CommonMessage.BillReject();
                    }
                    #region Save DAR

                    var locationData = _workorderems.LocationMasters.Where(x => x.LocationId == LocationId &&
                                                                           x.IsDeleted == false).FirstOrDefault();
                    objDAR.ActivityDetails = DarMessage.BillApprovedReject(userDataItem.FirstName + "" + userDataItem.LastName, locationData.LocationName, ApproveStatus);
                    objDAR.TaskType        = (long)TaskTypeCategory.BillApprovedReject;
                    objDAR.UserId          = UserId;
                    objDAR.CreatedBy       = UserId;
                    objDAR.LocationId      = LocationId;
                    objDAR.CreatedOn       = DateTime.UtcNow;
                    CommonManager.SaveDAR(objDAR);
                    #endregion DAR
                }
                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.spGetVendorAllDetail(Obj.VendorId).
                                       Select(x => new BillListApproveModel()
                        {
                            Email = x.COD_Email,
                        }).FirstOrDefault();
                        if (userData != null)
                        {
                            bool IsSent         = false;
                            var  objEmailHelper = new EmailHelper();
                            objEmailHelper.emailid       = userData.Email;
                            objEmailHelper.LocationName  = Obj.LocationName;
                            objEmailHelper.VendorName    = Obj.VendorName;
                            objEmailHelper.UserName      = userDataItem.FirstName + " " + userDataItem.LastName;
                            objEmailHelper.MailType      = "APPROVEBILL";
                            objEmailHelper.SentBy        = UserId;
                            objEmailHelper.LocationID    = LocationId;
                            objEmailHelper.TimeAttempted = DateTime.UtcNow.ToMobileClientTimeZone(objTemplateModel.TimeZoneName, objTemplateModel.TimeZoneOffset, objTemplateModel.IsTimeZoneinDaylight, false).ToString();
                            IsSent = objEmailHelper.SendEmailWithTemplate();
                            var userDataApprove = _workorderems.LogBills.Join(_workorderems.UserRegistrations, q => q.LBLL_ModifiedBy, u => u.UserId, (q, u) => new { q, u }).
                                                  Where(x => x.q.LBLL_Id == Obj.LBLL_Id).FirstOrDefault();
                            //Push Notification
                            if (userDataApprove != null)
                            {
                                if (userDataApprove.u.DeviceId != null)
                                {
                                    string message = PushNotificationMessages.BillApprovedReject(objEmailHelper.LocationName, Obj.LBLL_Id, ApproveStatus, objEmailHelper.UserName);
                                    PushNotification.GCMAndroid(message, userDataApprove.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  = LocationId;
                                    objEmailog.ModifiedBy  = null;
                                    objEmailog.ModifiedOn  = null;
                                    objEmailog.SentBy      = UserId;
                                    objEmailog.SentEmail   = userData.Email;
                                    objEmailog.Subject     = objEmailHelper.Subject;
                                    objEmailog.SentTo      = Obj.VendorId;
                                    objListEmailog.Add(objEmailog);
                                }
                                catch (Exception)
                                {
                                    throw;
                                }
                            }
                            using (var context = new workorderEMSEntities())
                            {
                                context.EmailLogs.AddRange(objListEmailog);
                                context.SaveChanges();
                            }
                            #endregion Email
                        }
                    }
                    else
                    {
                        result = "Somethinsg goes wrong.";
                    }
                }
                return(result);
            }
            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;
            }
        }