Exemplo n.º 1
0
        public void UpdateRecordMail_Validating(List <AttachHelp> attachHelp, RecordMail o)
        {
            AddUpdateRecordMail_Validating(o);
            var exist = GetRecordMail(o.Id);

            if (exist == null)
            {
                throw new ValidatingException("Item does not exist");
            }
            AddUpdateRecordMail_Validating(exist);
            if (exist.Date.Month != o.Date.Month || exist.Date.Year != o.Date.Year)
            {
                throw new ValidatingException("Date record of Month and Year can't modified!");
            }
            using (var con = Connection)
            {
                var col = con.GetCollection <RecordMail>(typeof(RecordMail).Name);
                if (attachHelp.Count > 0)
                {
                    var addfiles = attachHelp.Where(p => p.Todo == AttachHelp.State.Add).Select(p => p.Attach);
                    UploadFileMailAttach(addfiles, o);
                    var removeFile = attachHelp.Where(p => p.Todo == AttachHelp.State.Remove).Select(p => p.Attach)?.ToArray();
                    DeleteFileMailAttach(removeFile);
                }
                col.Update(o);
            }
        }
 public void AddRecordMailAttachment_ValidatingOnly(RecordMail mail, params RecordMailAttachment[] atts)
 {
     foreach (var a in atts)
     {
         if (string.IsNullOrWhiteSpace(a.Name))
         {
             throw new ValidatingException("Invalid filename");
         }
     }
 }
Exemplo n.º 3
0
        public RecordMail GetRecordMail(int id)
        {
            RecordMail o = null;

            using (var con = Connection)
            {
                var col = con.GetCollection <RecordMail>(typeof(RecordMail).Name);
                o = col.FindById(id);
            }
            return(o);
        }
Exemplo n.º 4
0
 public void AddRecordMail_Validating(List <AttachHelp> attachHelp, RecordMail o)
 {
     AddUpdateRecordMail_Validating(o);
     using (var con = Connection)
     {
         var col = con.GetCollection <RecordMail>(typeof(RecordMail).Name);
         if (attachHelp.Count > 0)
         {
             var addfiles = attachHelp.Where(p => p.Todo == AttachHelp.State.Add).Select(p => p.Attach);
             UploadFileMailAttach(addfiles, o);
         }
         col.Insert(o);
     }
 }
Exemplo n.º 5
0
 void AddUpdateRecordMail_Validating(RecordMail o)
 {
     if (o == null)
     {
         throw new ValidatingException("Invalid object");
     }
     if (string.IsNullOrWhiteSpace(o.Detail))
     {
         throw new ValidatingException("Invalid Detail");
     }
     if (o.Monthly.HasValue)
     {
         RecordMailMonthlySaved_IsValid(o.Monthly.Value, true);
     }
 }
Exemplo n.º 6
0
        public RecordMail Prev_RecordMail(RecordMail m)
        {
            var list = GetRecordMails();

            if (m == null)
            {
                return(list.LastOrDefault());
            }
            int index = list.IndexOf(list.SingleOrDefault(p => p.Id == m.Id)) - 1;

            if (index > -1)
            {
                return(list[index]);
            }
            return(null);
        }
Exemplo n.º 7
0
        public bool RemoveRecordMail(int id)
        {
            bool state = false;

            using (var con = Connection)
            {
                var        col = con.GetCollection <RecordMail>(typeof(RecordMail).Name);
                RecordMail m   = col.FindById(id);
                if (m == null)
                {
                    throw new ValidatingException("Item does not exist!");
                }
                if (m.Monthly.HasValue)
                {
                    RecordMailMonthlySaved_IsValid(m.Monthly.Value, true);
                }
                DeleteFileMailAttach(m.Attach);
                state = col.Delete(id);
            }
            return(state);
        }
        protected void UploadFileMailAttach(IEnumerable <RecordMailAttachment> files, RecordMail rm)
        {
            string opName  = $"{GetOperator(rm.OperatorId)?.Name}";
            string dateStr = $"{rm.Date:MMyyyy}";
            string path    = Path.Combine(FilePath, opName, dateStr);
            var    dir     = Directory.CreateDirectory(path);
            var    attach  = new List <RecordMailAttachment>();

            foreach (var source in files)
            {
                string newFilename = $"{Path.GetFileNameWithoutExtension(source.Name)}_{DateTime.Now.ToString("ddMMyyHHmmss")}{Path.GetExtension(source.Name)}";
                string newPath     = Path.Combine(path, newFilename);
                File.Copy(source.Path, newPath);
                attach.Add(new RecordMailAttachment()
                {
                    Name = source.Name,
                    Path = Path.Combine(opName, dateStr, newFilename),
                });
            }
            //in case add action only
            if (rm.Attach == null && attach.Any())
            {
                rm.Attach = attach.ToArray();
            }
            //in case update on exist object with new attachments
            else if (rm.Attach.Any())
            {
                var t = new List <RecordMailAttachment>(rm.Attach);
                t.AddRange(attach);
                rm.Attach = t.ToArray();
            }
        }