public ActionResult Create(JournalViewModel journal)
        {
            if (ModelState.IsValid)
            {
                var newJournal = Mapper.Map <JournalViewModel, Journal>(journal);
                JournalHelper.PopulateFile(journal.File, newJournal);

                newJournal.UserId = (int)_membershipService.GetUser().ProviderUserKey;

                var opStatus = _journalRepository.AddJournal(newJournal);
                if (!opStatus.Status)
                {
                    throw new System.Web.Http.HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
                }

                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(journal));
            }
        }
Ejemplo n.º 2
0
 public async Task AddJournal(Journal journal)
 {
     await _journalRepository.AddJournal(journal);
 }
Ejemplo n.º 3
0
        public async Task AddNewJournal(string name, string writer, string printdate, string publisher, string genre, string discount, string quantity, string price, string subject)
        {
            if (name == "" || writer == "" || printdate == "" || publisher == "" || genre == "" || discount == "" || quantity == "" || price == "" || subject == "")
            {
                await GeneralLibraryLogic.SaveToLogFile("All journal fields must be full");

                throw new BLLJournalException("All journal fields must be full");
            }
            Journal j1 = new Journal();

            j1.Name   = name;
            j1.Writer = writer;
            DateTime date;

            if (DateTime.TryParse(printdate, out date) == false)
            {
                await GeneralLibraryLogic.SaveToLogFile("Cannot convert printdate To DateTime!");

                throw new BLLJournalException("Cannot convert printdate To DateTime!");
            }
            j1.PrintDate = date;
            j1.Publisher = publisher;
            try
            {
                Genre g1 = await _genreRep.GetGenre(genre);

                if (g1.Name == null)
                {
                    g1.Name = genre;
                    await _genreRep.AddGenre(g1);

                    g1 = await _genreRep.GetGenre(genre);
                }
                j1.Genre = g1;
            }
            catch (Exception e)
            {
                if (e is GenreException ||
                    e is DALException)
                {
                    await GeneralLibraryLogic.SaveToLogFile(e.ToString());

                    throw new BLLJournalException("Cannot add a new journal atm try again later or call a manager");
                }
                else
                {
                    await GeneralLibraryLogic.SaveToLogFile(e.ToString());

                    throw new LibraryException("Unknown error inform a manager!");
                }
            }

            int discountToAdd = 0;

            if (int.TryParse(discount, out discountToAdd) == false)
            {
                await GeneralLibraryLogic.SaveToLogFile("Discount must be a number!");

                throw new BLLJournalException("Discount must be a number!");
            }
            if (discountToAdd < 0 || discountToAdd > 99)
            {
                await GeneralLibraryLogic.SaveToLogFile("Discount must be between 0-99");

                throw new BLLJournalException("Discount must be between 0-99");
            }
            j1.Discount = discountToAdd;
            int quantityToAdd = 0;

            if (int.TryParse(quantity, out quantityToAdd) == false)
            {
                await GeneralLibraryLogic.SaveToLogFile("Quantity must be a number!");

                throw new BLLJournalException("Quantity must be a number!");
            }
            if (quantityToAdd < 0)
            {
                await GeneralLibraryLogic.SaveToLogFile("Quantity cannot be negative!");

                throw new BLLJournalException("Quantity cannot be negative!");
            }
            j1.Quantity = quantityToAdd;
            int priceToAdd = 0;

            if (int.TryParse(price, out priceToAdd) == false)
            {
                await GeneralLibraryLogic.SaveToLogFile("Price must be a number!");

                throw new LibraryException("Price must be a number!");
            }
            if (priceToAdd < 0)
            {
                await GeneralLibraryLogic.SaveToLogFile("Price cannot be negative!");

                throw new LibraryException("Price cannot be negative!");
            }
            j1.Price   = priceToAdd;
            j1.Subject = subject;
            try
            {
                await _journalRep.AddJournal(j1);
            }
            catch (Exception e)
            {
                if (e is JournalException ||
                    e is DALException)
                {
                    await GeneralLibraryLogic.SaveToLogFile(e.ToString());

                    throw new BLLJournalException("Cannot add a new journal atm try again later or call a manager");
                }
                else
                {
                    await GeneralLibraryLogic.SaveToLogFile(e.ToString());

                    throw new LibraryException("Unknown error inform a manager!");
                }
            }
        }