public async Task <IHttpActionResult> InsertDocument(DocumentsVM au)
        {
            //obtiene si tiene mensajes pendientes de leer en general retorna true o false
            var filestring = Upload.FilePath(au.FileDocument);

            au.StringFile = filestring;
            var response = await doc.InsertDocuments(au);

            return(Ok(response));
        }
Exemple #2
0
        public ActionResult SaveDoks(DocumentsVM Doks)
        {
            List <SessionListnew> list = Session["SesDet"] as List <SessionListnew>;

            if (list == null)
            {
                return(Redirect("Login/InLogin"));
            }
            else
            {
                Doks.CmpyCode = list[0].CmpyCode;
                Doks.UserName = list[0].user_name;
                return(Json(_DokService.SaveDoks(Doks), JsonRequestBehavior.AllowGet));
            }
        }
        public async Task <IActionResult> AddDocuments(int lotId, DocumentsVM vm)
        {
            var identityUser = await _userManager.GetUserAsync(HttpContext.User);

            var loggedInUser = _context.Owner.Find(identityUser.OwnerId);

            var lot = await _context.Lot.FindAsync(lotId);

            var uploadedFiles = HttpContext.Request.Form.Files;

            if (uploadedFiles.Count == 0)
            {
                ModelState.AddModelError("Files", "Please upload at least one file");
            }

            // Assume that every row has a file
            // There is not a method currently to make sure a name/description matches a file, and vice versa
            if (uploadedFiles.Count != vm.Files.Count)
            {
                ModelState.AddModelError("Files", "Please make sure every row has an uploaded file");
            }

            var submittedRows = new List <SunridgeHOA.Models.File>();

            foreach (var file in vm.Files)
            {
                var hasName = !String.IsNullOrEmpty(file.Name);
                var hasDesc = !String.IsNullOrEmpty(file.Description);

                // This was a blank row, can ignore
                if (!hasName && !hasDesc)
                {
                    continue;
                }

                if (String.IsNullOrEmpty(file.Name) || String.IsNullOrEmpty(file.Description))
                {
                    ModelState.AddModelError("Files", "Please make sure every file has a name and description");
                    break;
                }

                // Add the file row to the array, so we can safely ignore empty rows
                submittedRows.Add(file);
            }

            if (ModelState.IsValid)
            {
                //foreach (var file in submittedRows)
                for (var i = 0; i < submittedRows.Count; i++)
                {
                    var fileDesc = submittedRows[i];
                    var file     = uploadedFiles[i];

                    var webRootPath = _hostingEnv.WebRootPath;
                    var folder      = SD.LotDocsFolder;
                    var uploads     = Path.Combine(webRootPath, folder);
                    var name        = Path.GetFileNameWithoutExtension(file.FileName);
                    var extension   = Path.GetExtension(file.FileName);
                    //var dateExt = DateTime.Now.ToString("MMddyyyy");
                    var newFileName = $"{lot.LotNumber} - {name}{extension}";

                    // Add (#) to the end of the file if there are files with the same name
                    int copyCount = 0;
                    while (System.IO.File.Exists(Path.Combine(uploads, newFileName)))
                    {
                        copyCount++;
                        newFileName = $"{lot.LotNumber} - {name} ({copyCount}){extension}";
                    }

                    using (var filestream = new FileStream(Path.Combine(uploads, newFileName), FileMode.Create))
                    {
                        file.CopyTo(filestream);
                    }

                    var uploadFile = new SunridgeHOA.Models.File
                    {
                        FileURL          = $@"\{folder}\{newFileName}",
                        Name             = fileDesc.Name,
                        Description      = fileDesc.Description,
                        LastModifiedBy   = loggedInUser.FullName,
                        LastModifiedDate = DateTime.Now
                    };
                    _context.File.Add(uploadFile);

                    var lotHistory = new LotHistory
                    {
                        LotId            = lotId,
                        PrivacyLevel     = "Owner",
                        LastModifiedBy   = loggedInUser.FullName,
                        LastModifiedDate = DateTime.Now,
                        Files            = new List <SunridgeHOA.Models.File> {
                            uploadFile
                        }
                    };
                    _context.LotHistory.Add(lotHistory);
                }


                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(ViewFiles), new { id = lotId }));
            }

            ViewData["LotId"] = lotId;
            return(View());
        }
Exemple #4
0
        public async Task <Response <bool> > InsertDocuments(DocumentsVM doc)
        {
            Response <bool> response = new Response <bool>();

            try
            {
                using (var dc = new RentAppEntities())
                {
                    var query = dc.spInsDocument(doc.IdOwner, doc.IdAdmin, doc.Name, doc.FileDocument, doc.StringFile, ".pdf");
                    if (query == -1)
                    {
                        if (doc.IdOwner == null || doc.IdOwner == Guid.Empty)
                        {
                            //es para todos los usurios
                            var owner = await o.SelectOwnerAll(true);

                            foreach (var itemO in owner.Result)
                            {
                                Helpers.Notifications.Instance.NotificationsMessage(itemO.IdOwner, 1, "El administrador subio un nuevo documento");
                                var user = await u.GetUser(itemO.IdOwner, true);

                                foreach (var itemU in user.Result)
                                {
                                    Helpers.Notifications.Instance.NotificationsMessage(itemU.UserId, 0, "El administrador subio un nuevo documento");
                                }
                            }
                            //var user = await u.
                        }
                        else
                        {
                            //es para el propietario y los usuarios
                            var ownerFilter = await o.SelectOwnerAll(true);

                            var owner = ownerFilter.Result.Where(c => c.Status == true && c.IdOwner == doc.IdOwner).ToList();
                            foreach (var itemO in owner)
                            {
                                Helpers.Notifications.Instance.NotificationsMessage(itemO.IdOwner, 1, "El administrador subio un nuevo documento");
                                var user = await u.GetUser(itemO.IdOwner, true);

                                foreach (var itemU in user.Result)
                                {
                                    Helpers.Notifications.Instance.NotificationsMessage(itemU.UserId, 0, "El administrador subio un nuevo documento");
                                }
                            }
                        }
                        response.Count   = 1;
                        response.Message = null;
                        response.Result  = true;
                    }
                    else
                    {
                        response.Count   = 0;
                        response.Message = "No se pudo insertar el documento";
                        response.Result  = false;
                    }
                }
                return(response);
            }
            catch (Exception ex)
            {
                response.Count   = 0;
                response.Message = ex.Message;
                response.Result  = false;
                return(response);
            }
        }
        public DocumentsVM SaveDoks(DocumentsVM Doks)
        {
            try
            {
                if (!Doks.EditFlag)
                {
                    var Drecord = new List <string>();
                    List <DocumentsDetailnew> ObjList = new List <DocumentsDetailnew>();
                    ObjList.AddRange(Doks.DocumentsDetailnew.Select(m => new DocumentsDetailnew
                    {
                        CmpyCode = m.CmpyCode,
                        DocCode  = m.DocCode,
                        DocName  = m.DocName
                    }).ToList());
                    int n = 0;
                    n = ObjList.Count;


                    while (n > 0)
                    {
                        // int Doks1 = _EzBusinessHelper.ExecuteScalar("Select count(*) as [count1] from MDOC012 where CmpyCode='" + Doks.CmpyCode + "' and DocCode='" + ObjList[n - 1].DocCode + "'");
                        int Doks1 = _EzBusinessHelper.ExecuteScalar("Select count(*) as [count1] from HRDOCM001 where CmpyCode='" + Doks.CmpyCode + "' and HRDOCM001_CODE='" + ObjList[n - 1].DocCode + "'");
                        if (Doks1 == 0)
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.Append("'" + Doks.CmpyCode + "',");
                            sb.Append("'" + ObjList[n - 1].DocCode + "',");
                            sb.Append("'" + ObjList[n - 1].DocName + "')");
                            //sb.Append("'" + ObjList[n - 1].UniCodeName + "')");
                            //_EzBusinessHelper.ExecuteNonQuery("insert into MDOC012(CmpyCode,DocCode,DocName,UniCodeName) values(" + sb.ToString() + "");
                            _EzBusinessHelper.ExecuteNonQuery("insert into HRDOCM001(CMPYCODE,HRDOCM001_CODE,NAME) values(" + sb.ToString() + "");
                            Doks.SaveFlag     = true;
                            Doks.ErrorMessage = string.Empty;
                        }
                        else
                        {
                            Drecord.Add(ObjList[n - 1].DocCode.ToString());

                            Doks.Drecord      = Drecord;
                            Doks.SaveFlag     = false;
                            Doks.ErrorMessage = "Duplicate Record";
                        }
                        n = n - 1;
                    }


                    return(Doks);
                }

                //                            CMPYCODE
                //HRDOCM001_CODE
                //NAME
                var DoksEdit = _EzBusinessHelper.ExecuteScalar("Select count(*) from HRDOCM001 where CmpyCode='" + Doks.CmpyCode + "' and HRDOCM001_CODE='" + Doks.DocCode + "'");
                if (DoksEdit != 0)
                {
                    _EzBusinessHelper.ExecuteNonQuery("update HRDOCM001 set CmpyCode='" + Doks.CmpyCode + "',HRDOCM001_CODE='" + Doks.DocCode + "',NAME='" + Doks.DocName + "' where CmpyCode='" + Doks.CmpyCode + "' and HRDOCM001_CODE='" + Doks.DocCode + "'");
                    Doks.SaveFlag     = true;
                    Doks.ErrorMessage = string.Empty;
                }
                else
                {
                    Doks.SaveFlag     = false;
                    Doks.ErrorMessage = "Record not available";
                }
            }
            catch (Exception ex)
            {
                Doks.SaveFlag = false;
                //  unit.ErrorMessage = exceptionMessage;
            }
            return(Doks);
        }
Exemple #6
0
 public DocumentsVM SaveDoks(DocumentsVM Doks)
 {
     return(_DokRepo.SaveDoks(Doks));
 }