Beispiel #1
0
        public IHttpActionResult AddNotice(NoticeViewModel noticeView)
        {
            try
            {
                string errorMessage = String.Empty;
                Notice notice       = new Notice();
                if (notice != null)
                {
                    notice.Content         = noticeView.Content;
                    notice.NoticeCode      = noticeView.NoticeCode;
                    notice.Type            = noticeView.Type;
                    notice.IsSent          = false;
                    notice.CreatedDate     = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById(ConfigurationManager.AppSettings["LocalTimeZone"]));
                    notice.IsGeneratNotice = noticeView.memberId == 0 ? true : false;

                    if (noticeView.memberId != 0)
                    {
                        notice.MemberNotices = new List <MemberNotice>();
                        MemberNotice note = new MemberNotice();
                        note.MemberId = noticeView.memberId;
                        note.NoticeId = notice.ID;
                        note.IsOpened = false;
                        note.IsSent   = false;
                        notice.MemberNotices.Add(note);
                    }
                    notice = _notice.Add(notice, out errorMessage);
                }
                var messageData = new
                {
                    code = String.IsNullOrEmpty(errorMessage) ? Constant.SuccessMessageCode : Constant.ErrorMessageCode
                    ,
                    message = String.IsNullOrEmpty(errorMessage) ? Constant.MessageSuccess : errorMessage
                };
                var returnObject = new { messageCode = messageData, noticeId = notice.ID };
                return(Ok(returnObject));
            }
            catch (Exception ex)
            {
                string errorLogId   = _eventLog.WriteLogs(User.Identity.Name, ex, MethodBase.GetCurrentMethod().Name);
                var    messageData  = new { code = Constant.ErrorMessageCode, message = String.Format(Constant.MessageTaskmateError, errorLogId) };
                var    returnObject = new { messageCode = messageData };
                return(Ok(returnObject));
            }
        }
Beispiel #2
0
        public IActionResult Create(NoticeViewModel model)
        {
            var returnModel = new ReturnModel();

            if (!ModelState.IsValid)
            {
                returnModel.IsSuccess = false;
                returnModel.Message   = "Formu Eksiksiz Doldurunuz";
                return(Ok(returnModel));
            }

            var newNotice = new Notice
            {
                Description   = model.Notice.Description,
                Address       = model.Notice.Address,
                AgentId       = int.Parse(User.FindFirst(x => x.Type == ClaimTypes.NameIdentifier).Value),
                HouseAge      = model.Notice.HouseAge,
                IsActive      = true,
                IsFurnished   = model.Notice.IsFurnished,
                HouseType     = model.Notice.HouseType,
                NumberOfRooms = model.Notice.NumberOfRooms,
                SquareMeter   = model.Notice.SquareMeter,
                Price         = model.Notice.Price,
                StatusType    = model.Notice.StatusType,
                CreatedBy     = User.Identity.Name,
                CreatedDate   = DateTime.Now,
                UpdatedBy     = User.Identity.Name,
                UpdatedDate   = DateTime.Now
            };

            try
            {
                _noticeService.Add(newNotice);
                returnModel.IsSuccess = true;
                returnModel.Message   = "Kayıt Başarılı, Yönlendiriliyorsunuz";
            }
            catch (Exception ex)
            {
                returnModel.IsSuccess = false;
                returnModel.Message   = "Hata Oluştu" + ex.Message;
            }

            return(Ok(returnModel));
        }
Beispiel #3
0
        public JsonResult CheckReservation(string id, int status, string comment)
        {
            try {
                if (string.IsNullOrWhiteSpace(id))
                {
                    throw new ArgumentException("id");
                }

                var reservation = _reservationService.GetReservation(id);
                if (reservation == null)
                {
                    throw new iPemException("未找到数据对象");
                }

                reservation.Status = Enum.IsDefined(typeof(EnmResult), status) ? (EnmResult)status : EnmResult.Failure;
                if (reservation.Status == EnmResult.Success)
                {
                    var interval = 0d;
                    var rtValues = _workContext.RtValues();
                    if (rtValues != null)
                    {
                        interval = rtValues.gcyyshsxShiChang;
                    }

                    var now = DateTime.Now;
                    if (now >= reservation.ExpStartTime)
                    {
                        reservation.StartTime = now;
                    }
                    else
                    {
                        reservation.StartTime = now.AddMinutes(interval);
                        if (reservation.StartTime >= reservation.ExpStartTime)
                        {
                            reservation.StartTime = reservation.ExpStartTime;
                        }
                    }
                }

                _reservationService.Check(reservation.Id, reservation.StartTime, reservation.Status, comment);

                #region 通知服务重载配置
                if (reservation.Status == EnmResult.Success)
                {
                    _noteService.Add(new H_Note {
                        SysType = 2, GroupID = "-1", Name = "M_Reservations", DtType = 0, OpType = 0, Time = DateTime.Now, Desc = "同步工程预约"
                    });
                }
                #endregion

                #region 通知用户审核结果
                var newNotice = new H_Notice {
                    Id          = Guid.NewGuid(),
                    Title       = "工程预约审核结果",
                    Content     = reservation.Status == EnmResult.Failure ? string.Format("您于 [ {0} ] 申请的工程预约 [ {1} ] 由于 [ {2} ] 原因,审核未通过。", reservation.ExpStartTime, reservation.Name, comment) : string.Format("您于 [ {0} ] 申请的工程预约 [ {1} ] 已通过审核,该预约将于[ {2} ]生效。", reservation.ExpStartTime, reservation.Name, reservation.StartTime),
                    CreatedTime = DateTime.Now,
                    Enabled     = true
                };

                var roleId         = _roleService.GetRoleByUid(reservation.UserId).Id;
                var toUsers        = _userService.GetUsersInRole(roleId, false);
                var noticesInUsers = toUsers.Select(u => new H_NoticeInUser {
                    NoticeId = newNotice.Id,
                    UserId   = u.Id,
                    Readed   = false,
                    ReadTime = DateTime.MinValue
                });

                _noticeService.Add(newNotice);
                _noticeInUserService.Add(noticesInUsers.ToArray());
                #endregion

                _webLogger.Information(EnmEventType.Other, string.Format("审核工程预约[ {0} ],审核结果:[ {1} ],预约编号:[ {2} ],预期开始时间:[ {3} ],实际开始时间:[ {4} ],结束时间:[ {5} ],创建人员:[ {6} ],备注[ {7} ]", reservation.Name, Common.GetResStatusDisplay(reservation.Status), reservation.Id, CommonHelper.DateTimeConverter(reservation.ExpStartTime), CommonHelper.DateTimeConverter(reservation.StartTime), CommonHelper.DateTimeConverter(reservation.EndTime), reservation.Creator, reservation.Comment), _workContext.User().Id, null);
                return(Json(new AjaxResultModel {
                    success = true, code = 200, message = "审核完成"
                }));
            } catch (Exception exc) {
                _webLogger.Error(EnmEventType.Other, exc.Message, _workContext.User().Id, exc);
                return(Json(new AjaxResultModel {
                    success = false, code = 400, message = exc.Message
                }));
            }
        }