Example #1
0
        public async Task <JsonResult> OnPostUpdate([DataSourceRequest] DataSourceRequest request, RentalSchedularViewModel rental)
        {
            if (ModelState.IsValid)
            {
                var updateData = await _context.RentalReservations
                                 .Where(a => a.Id == rental.RentalId).FirstOrDefaultAsync();

                if (updateData == null)
                {
                    ModelState.AddModelError("Finns ej", "Finns inte i databasen.");
                    return(new JsonResult(new[] { rental }.ToDataSourceResult(request, ModelState)));
                }

                updateData.Description = rental.Description;
                updateData.PickupDate  = rental.Start;
                updateData.ReturnDate  = rental.End;

                await _context.RentalReservations.AddAsync(updateData);

                _context.Entry(updateData).State = EntityState.Modified;
                await _context.SaveChangesAsync();
            }


            return(new JsonResult(new[] { rental }.ToDataSourceResult(request, ModelState)));
        }
Example #2
0
        public async Task <IActionResult> PutDrainPatrolAlarm(long id, DrainPatrolAlarm drainPatrolAlarm)
        {
            if (id != drainPatrolAlarm.Id)
            {
                return(BadRequest());
            }

            _context.Entry(drainPatrolAlarm).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DrainPatrolAlarmExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #3
0
        public async Task <IActionResult> PutPremise(long id, Premise premise)
        {
            if (id != premise.Id)
            {
                return(BadRequest());
            }

            _context.Entry(premise).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PremiseExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #4
0
        public async Task <IActionResult> PutWellMaintenanceWork(long id, WellMaintenanceWork wellMaintenanceWork)
        {
            if (id != wellMaintenanceWork.Id)
            {
                return(BadRequest());
            }

            _context.Entry(wellMaintenanceWork).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WellMaintenanceWorkExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutActivityPerRow(long id, ActivityPerRow activityPerRow)
        {
            if (id != activityPerRow.Id)
            {
                return(BadRequest());
            }

            _context.Entry(activityPerRow).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ActivityPerRowExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <IssueReport> > PostIssueReport(IssueReportViewModel issueReport)
        {
            var well = await _context.Wells.Where(a => a.WellName == issueReport.WellName).FirstOrDefaultAsync();

            var insertData = new IssueReport
            {
                WellId                   = well.Id,
                ProblemDescription       = issueReport.ProblemDescription,
                SolutionDescription      = issueReport.SolutionDescription,
                NewActivatorSerialNumber = issueReport.NewActivatorSerialNumber,
                NewValveSerialNumber     = issueReport.NewValveSerialNumber,
                IsChargeable             = issueReport.IsChargeable,
                Photo = issueReport.ImageName,
                OldActivatorSerialNumber = well.ActivatorSerialNumber,
                OldValveSerialNumber     = well.ValveSerialNumber,
                TimeForAlarm             = issueReport.TimeForAlarm,
                ArrivalTime  = issueReport.ArrivalTime,
                TimeToRepair = issueReport.TimeToRepair,
                CreatedAt    = issueReport.CreatedAt,
                UpdatedAt    = issueReport.CreatedAt
            };

            well.ActivatorSerialNumber = string.IsNullOrEmpty(issueReport.NewActivatorSerialNumber) ? well.ActivatorSerialNumber : issueReport.NewActivatorSerialNumber;
            well.ValveSerialNumber     = string.IsNullOrEmpty(issueReport.NewValveSerialNumber) ? well.ValveSerialNumber : issueReport.NewValveSerialNumber;
            well.UpdatedAt             = DateTime.UtcNow;

            await _context.AddAsync(well);

            _context.Entry(well).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            _context.IssueReports.Add(insertData);
            await _context.SaveChangesAsync();

            // return CreatedAtAction("GetIssueReport", new { id = issueReport.Id }, issueReport);
            return(Ok(issueReport));
        }
Example #7
0
        public async Task <JsonResult> OnPostUpload(string path, IFormFile file)

        {
            if (file != null)
            {
                var fileContent = Microsoft.Net.Http.Headers.ContentDispositionHeaderValue.Parse(file.ContentDisposition);
                var fileName    = System.IO.Path.GetFileName(fileContent.FileName.ToString().Trim('"'));

                var filePath = Path.GetTempFileName();

                var directory = await _context.UploadFileDirectories
                                .Where(a => a.Directory == path)
                                .FirstOrDefaultAsync();

                long size = file.Length;

                //  await UploadFileBlobAsync(filePath, fileName);

                string result = await UploadFile(file, filePath);

                if (result == "OK")
                {
                    var user = await _userManager.GetUserAsync(HttpContext.User);

                    var fileExit = await _context.UploadedFiles.Where(o => o.FileName == fileName && o.Directory == path && o.Container == MyConsts.boardDocuments).FirstOrDefaultAsync();

                    if (fileExit != null)
                    {
                        fileExit.UpdatedAt    = DateTime.Now;
                        fileExit.AspNetUserId = user.Id;

                        _context.UploadedFiles.Add(fileExit);
                        _context.Entry(fileExit).State = EntityState.Modified;
                        await _context.SaveChangesAsync();
                    }
                    else
                    {
                        var insertData = new UploadedFile
                        {
                            FileName              = fileName,
                            Path                  = directory.Directory + "/" + fileName,
                            Size                  = size,
                            Directory             = directory.Directory,
                            Container             = MyConsts.boardDocuments,
                            UploadFileDirectoryId = directory.Id,
                            UploadFileCategoryId  = directory.UploadFileCategoryId,
                            HasDirectories        = false,
                            IsDirectory           = false,
                            CreatedAt             = DateTime.Now,
                            UpdatedAt             = DateTime.Now,
                            AspNetUserId          = user.Id
                        };

                        _context.UploadedFiles.Add(insertData);
                        await _context.SaveChangesAsync();
                    }
                }

                Message = fileName + " är nu sparad.";
            }


            var lovaDirectories = await _context.UploadFileDirectories
                                  .Where(a => a.UploadFileCategoryId == 2 && string.IsNullOrEmpty(path)?a.Directory != path : a.Directory == "apa")
                                  .Select(a => new ViewFilesViewModel
            {
                Name           = a.Directory,
                Path           = a.Directory,
                Size           = 0,
                Created        = DateTime.Now,
                CreatedUtc     = DateTime.Now,
                Modified       = DateTime.Now,
                ModifiedUtc    = DateTime.Now,
                HasDirectories = false,
                IsDirectory    = true,
                Extension      = ""
            })
                                  .ToArrayAsync();

            var lovaFiles = await _context.UploadedFiles
                            .Where(a => a.UploadFileCategoryId == 2 && a.IsDirectory == false && a.Directory == path)
                            .Select(a => new ViewFilesViewModel
            {
                Name           = Path.GetFileNameWithoutExtension(a.FileName),
                Path           = a.Path,
                Size           = a.Size,
                Created        = a.CreatedAt,
                CreatedUtc     = a.CreatedAt,
                Modified       = a.UpdatedAt,
                ModifiedUtc    = a.UpdatedAt,
                HasDirectories = a.HasDirectories,
                IsDirectory    = a.IsDirectory,
                Extension      = Path.GetExtension(a.FileName)
            })
                            .ToArrayAsync();

            var files = lovaDirectories.Concat(lovaFiles);


            return(new JsonResult(files));
        }
Example #8
0
        public async Task OnPost(IFormFile files)
        {
            if (files != null)
            {
                var fileContent = Microsoft.Net.Http.Headers.ContentDispositionHeaderValue.Parse(files.ContentDisposition);
                var fileName    = System.IO.Path.GetFileName(fileContent.FileName.ToString().Trim('"'));

                var filePath = Path.GetTempFileName();

                var directory = await _context.UploadFileDirectories
                                .Where(a => a.Id == FileUpload.UploadFileDirectoryId)
                                .FirstOrDefaultAsync();

                long size = files.Length;

                //  await UploadFileBlobAsync(filePath, fileName);

                // string container = FileUpload.UploadFileCategoryId == 1 ? MyConsts.lovaDocuments : MyConsts.lottingelundDocuments;

                string container = "";

                switch (FileUpload.UploadFileCategoryId)
                {
                case 1:
                    container = MyConsts.lovaDocuments;
                    break;

                case 2:
                    container = MyConsts.boardDocuments;
                    break;

                default:
                    container = MyConsts.lottingelundDocuments;
                    break;
                }



                string result = await UploadFile(files, filePath, container);



                if (result == "OK")
                {
                    var user = await _userManager.GetUserAsync(HttpContext.User);

                    var fileExit = await _context.UploadedFiles.Where(o => o.FileName == fileName && o.Directory == directory.Directory && o.Container == container).FirstOrDefaultAsync();

                    if (fileExit != null)
                    {
                        fileExit.UpdatedAt    = DateTime.Now;
                        fileExit.AspNetUserId = user.Id;

                        _context.UploadedFiles.Add(fileExit);
                        _context.Entry(fileExit).State = EntityState.Modified;
                        await _context.SaveChangesAsync();
                    }
                    else
                    {
                        var insertData = new UploadedFile
                        {
                            FileName              = fileName,
                            Path                  = directory.Directory + "/" + fileName,
                            Size                  = size,
                            Directory             = directory.Directory,
                            UploadFileDirectoryId = FileUpload.UploadFileDirectoryId,
                            UploadFileCategoryId  = FileUpload.UploadFileCategoryId,
                            Container             = container,
                            HasDirectories        = false,
                            IsDirectory           = false,
                            CreatedAt             = DateTime.Now,
                            UpdatedAt             = DateTime.Now,
                            AspNetUserId          = user.Id
                        };

                        _context.UploadedFiles.Add(insertData);
                        await _context.SaveChangesAsync();
                    }
                }

                Message = fileName + " är nu sparad.";
            }
        }
Example #9
0
        public async Task <IActionResult> OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }


            var well = await _context.Wells.Where(a => a.WellName == IssueReportViewModel.WellName).FirstOrDefaultAsync();

            if (well == null)
            {
            }

            var user = await _userManager.GetUserAsync(HttpContext.User);

            var fileName = "";

            if (IssueReportViewModel.File != null)
            {
                var fileContent = Microsoft.Net.Http.Headers.ContentDispositionHeaderValue.Parse(IssueReportViewModel.File.ContentDisposition);
                fileName = Path.GetFileName(fileContent.FileName.ToString().Trim('"'));
                var filePath = Path.GetTempFileName();

                string result = await UploadFile(IssueReportViewModel.File, filePath);
            }


            IssueReport insertData = new IssueReport
            {
                WellId                   = well.Id,
                ProblemDescription       = IssueReportViewModel.ProblemDescription,
                SolutionDescription      = IssueReportViewModel.SolutionDescription,
                NewActivatorSerialNumber = IssueReportViewModel.NewActivatorSerialNumber,
                NewValveSerialNumber     = IssueReportViewModel.NewValveSerialNumber,
                OldActivatorSerialNumber = well.ActivatorSerialNumber,
                OldValveSerialNumber     = well.ValveSerialNumber,
                IsChargeable             = IssueReportViewModel.IsChargeable,
                IsPhoto                  = IssueReportViewModel.IsPhoto,
                IsLowVacuum              = IssueReportViewModel.IsLowVacuum,
                MasterNode               = IssueReportViewModel.MasterNode + 1,
                Photo        = fileName,
                Alarm        = IssueReportViewModel.Alarm + 1,
                TimeForAlarm = IssueReportViewModel.TimeForAlarm,
                ArrivalTime  = IssueReportViewModel.ArrivalTime,
                TimeToRepair = IssueReportViewModel.TimeToRepair,
                AspNetUserId = user.Id,
                CreatedAt    = DateTime.UtcNow,
                UpdatedAt    = DateTime.UtcNow
            };

            well.ActivatorSerialNumber = string.IsNullOrEmpty(IssueReportViewModel.NewActivatorSerialNumber) ? well.ActivatorSerialNumber : IssueReportViewModel.NewActivatorSerialNumber;
            well.ValveSerialNumber     = string.IsNullOrEmpty(IssueReportViewModel.NewValveSerialNumber) ? well.ValveSerialNumber : IssueReportViewModel.NewValveSerialNumber;
            well.UpdatedAt             = DateTime.UtcNow;

            await _context.AddAsync(well);

            _context.Entry(well).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            _context.IssueReports.Add(insertData);
            await _context.SaveChangesAsync();

            return(RedirectToPage("WaterDrainReport"));
        }