public ActionResult SaveDischarge(SaveDischargeCommand command, HttpPostedFileBase discharge)
        {
            command.File = discharge.InputStream;
            command.FileName = discharge.FileName;
            command.Size = discharge.ContentLength;
            command.ContentType = discharge.ContentType;

            var answer = _noticesService.SaveDischarge(command);
            return RedirectToAction("Index", "HospitalUserHomePage", new GetHospitalNoticesPageInformationCommand { Token = answer.Token });
        }
Exemplo n.º 2
0
        public SaveDischargeCommandAnswer SaveDischarge(SaveDischargeCommand command)
        {
            var user = _tokenManager.GetUserByToken(command.Token);

            var hospital = _hospitalManager.GetHospitalByUser(user);

            var responsiblePersonId = _clinicUserRepository.GetModels()
                .FirstOrDefault(model => model.ClinicId == command.ClinicId && model.IsDischargeResponsiblePerson).Id;

            var anotherPersonsFromClinic = _clinicUserRepository.GetModels()
                .Where(model => model.ClinicId == command.ClinicId && !model.IsDischargeResponsiblePerson).Select(model => model.Id).ToList();

            var titleMessage = $"Новая выписка была отправлена из больницы '{hospital.Name}'";
            var textMessage =
                $"Новая выписка была отправлена из больницы '{hospital.Name}'. Отправитель '{user.Name}'. Дата: '{DateTime.Now.ToCorrectDateString()} {DateTime.Now.ToString("t")}' ";

            var body = ReadFully(command.File);

            var discharge = new DischargeStorageModel
            {
                Id = 0,
                Name = command.FileName,
                Message = new MessageStorageModel
                {
                    Id = 0,
                    Title = titleMessage,
                    Date = DateTime.Now,
                    Text = textMessage,
                    ShowStatus = TwoSideShowStatus.Showed,
                    UserFromId = user.Id,
                    UserToId = responsiblePersonId,
                    IsRead = false,
                    MessageType = MessageType.WarningMessage,
                },
                Body = body,
                MimeType = command.ContentType
            };
            this._dischargeRepository.Add(discharge);

            foreach (var personId in anotherPersonsFromClinic)
            {
                var message = new MessageStorageModel
                {
                    Id = 0,
                    Title = titleMessage,
                    Date = DateTime.Now,
                    Text = textMessage,
                    ShowStatus = TwoSideShowStatus.Showed,
                    UserFromId = user.Id,
                    UserToId = personId,
                    IsRead = false,
                    MessageType = MessageType.WarningMessage,
                };
                _messageRepository.Add(message);
            }
            _messageRepository.SaveChanges();

            return new SaveDischargeCommandAnswer
            {
                Token = command.Token.Value
            };
        }